Begin change

Example: Creating a traversable IFS tree
(File three of three)

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 Lists.
// 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 com.ibm.as400.access.AS400;
import com.ibm.as400.util.html.HTMLMeta;
import com.ibm.as400.util.html.HTMLHeading;
import com.ibm.as400.util.html.HTMLConstants;
import com.ibm.as400.util.html.FileListElement;

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

//
// An example of using the FileListElement class in a servlet.
//

public class TreeList extends HttpServlet
{
   private AS400 sys_;
   /**
    *  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");

      try
      {  
         PrintWriter out = resp.getWriter();
         out.println("<html>\n");
         out.println(new HTMLMeta("Expires","Mon, 02 Jan 1990 13:00:00 GMT"));
         out.println("<body>\n");

         // If the path parameter is not null, then the user has
         // selected an element from the FileTreeElement list in
         // the navigation frame.
         if (req.getPathInfo() != null)
         {
            // Create a FileListElement passing in an AS400 system
            // object and the Http servlet request. The request will
            // contain the necessary path information to list out the
            // contents of the FileTreeElement (directory) selected.
            FileListElement fileList = new FileListElement(sys_, req);

            // Display the FileListElement contents.
            out.println(fileList.list());
         }
         else  // Display this HTMLHeading if no FileTreeElement has been selected.
         {
            HTMLHeading heading = new HTMLHeading(1,"An HTML File List Example");
            heading.setAlign(HTMLConstants.CENTER);
            out.println(heading.getTag());
         }

         out.println("</body>\n");
         out.println("</html>\n");
         out.close();    
      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
   }

   /**
     *  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 init(ServletConfig config)
       throws ServletException
    {
       super.init(config);

       // Create an AS400 object.
       sys_ = new AS400("mySystem", "myUserID", "myPassword");
    }           
}
End change