範例:建立可遍訪的整合檔案系統樹(檔案 3 之 1)

IBM® Toolbox for Java™ 程式碼範例與其他兩個範例檔中的程式碼結合,在 Servlet 中顯示 HTMLTree 及 FileListElement。

範例中的三個檔案為:

註: 請閱讀程式碼範例免責聲明中的重要法律資訊。
///////////////////////////////////////////////////////////////////////////////
//
// This source is an example of using the HTML package
// classes, which allow you to easily build HTML and File Trees.
//
///////////////////////////////////////////////////////////////////////////////

import java.io.PrintWriter;
import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.*;

import com.ibm.as400.util.html.HTMLMeta;


//
// An example of using frames to display an HTMLTree and FileListElement
// in a servlet.
//

public class FileTreeExample extends HttpServlet 
{
    public void init(ServletConfig config)
      throws ServletException
   {
       super.init(config);
   }

   /**
    *  Process the GET request.
    *  @param req The request.
    *  @param res The response.
    **/

      public void doGet (HttpServletRequest req, HttpServletResponse resp) 
       throws ServletException, IOException
   {  
      resp.setContentType("text/html");
      
      // Set up two frames. The first, a navigation frame, will display
// the HTMLTree, which will contain FileTreeElements and allow 
      // navigation of the File system.The second frame will display/list 
// the contents of a selected directory from the navigation frame.
      PrintWriter out = resp.getWriter();
      out.println("<html>\n");
      out.println(new HTMLMeta("Expires","Mon, 04 Jan 1990 13:00:00 GMT"));
      out.println("<frameset cols=\"25%,*\">");
      out.println("<frame frameborder=\"5\" src=\"/servlet/TreeNav\" name=\"nav\">");
      out.println("<frame frameborder=\"3\" src=\"/servlet/TreeList\" name=\"list\">");
      out.println("</frameset>");
      out.println("</html>\n");
      out.close();
   }
   
   /**
    *  Process the POST request.
    *  @param req The request.
    *  @param res The response.
    **/

   public void doPost (HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
   {  
      res.setContentType("text/html");
      ServletOutputStream out = res.getOutputStream();
   }
   
   public void destroy(ServletConfig config)
   {  
      // do nothing
   }
   
   public String getServletInfo()
   {
      return "FileTree Servlet";
   }
}