This example code, in conjunction with the code in the other two example files, displays an HTMLTree and FileListElement in a servlet. The three files in the example are:
///////////////////////////////////////////////////////////////////////// // // This source is an example of using the IBM Toolbox for Java HTML // package classes, which allow you to easily build HTML and File Trees. // IBM grants you a nonexclusive license to use this as an example // from which you can generate similar function tailored to // your own specific needs. // // This sample code is provided by IBM for illustrative purposes // only. These examples have not been thoroughly tested under all // conditions. IBM, therefore, cannot guarantee or imply // reliability, serviceability, or function of these programs. // // All programs contained herein are provided to you "AS IS" // without any warranties of any kind. The implied warranties of // merchantablility and fitness for a particular purpose are // expressly disclaimed. // // IBM Toolbox for Java // (C) Copyright IBM Corp. 1997, 1999 // All rights reserved. // US Government Users Restricted Rights - // Use, duplication, or disclosure restricted // by GSA ADP Schedule Contract with IBM Corp. // ///////////////////////////////////////////////////////////////////////// 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"; } }