This IBM® Toolbox for Java™ 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 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";
}
}