All pastes #267799 Raw Edit

Stuff

public text v1 · immutable
·published 2006-12-05 02:47 UTC
rendered paste body
package java112.project4;
import java112.employee.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *  This class demonstrates getting input fields from an HTML form
 *
 *@author    Sirirut Jaikongla
 */
public class StartupServlet extends HttpServlet {
    private  Properties         props;
    private  EmployeeDirectory  ed;


    /**
     *  Description of the Method
     */
    public void init() {

        ServletConfig   config   = getServletConfig();
        ServletContext  context  = config.getServletContext();

        try {
            if (context.getAttribute("projectProperties") == null) {
                loadProperties();
                context.setAttribute("projectProperties", props);
            }
            else {
                props = (Properties) context.getAttribute("projectProperties");
            }
            ed = new EmployeeDirectory();
            ed.load(props.getProperty("employ.file"));
        }
        catch (IOException ioe) {
            System.out.println("Can't load the properties file");
            ioe.printStackTrace();
        }
        catch (Exception e) {
            System.out.println("Problem: " + e);
            e.printStackTrace();
        }

    }


    /**
     *  loadProperties Method
     */
    public void loadProperties() {
        props = new Properties();
        try {
            props.load(this.getClass().getResourceAsStream("C:\\projects\\config\\project4.properties"));
        }
        catch (java.io.IOException ioe) {
            System.out.println("Can't load the properties file");
            ioe.printStackTrace();
        }
        catch (java.lang.Exception e) {
            System.out.println("Problem: " + e);
            e.printStackTrace();
        }
    }


    /**
     *  Description of the Method
     *
     *@param  request               Description of the Parameter
     *@param  res                   Description of the Parameter
     *@exception  ServletException  Description of the Exception
     *@exception  IOException       Description of the Exception
     */
    public void doGet(HttpServletRequest request, HttpServletResponse res)
             throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter  out       = res.getWriter();
        out.print("<HTML>");
        out.print("<HEAD><TITLE>Project2/First112Servlet Output</TITLE></HEAD>");
        out.print("<BODY bgcolor=white>");


        List         eList     = (ArrayList) ed.getEmpList();
        Employee     e;
        e = (Employee) eList.get(0);
        out.println(e.toString());

        Map          eMapId    = (HashMap) ed.getMapId();
        Set          es        = eMapId.entrySet();
        Iterator     i         = es.iterator();
        Map.Entry    me        = (Map.Entry) i.next();
        e = (Employee) me.getValue();
        out.println(e.toString());

        Map          eMapLast  = (HashMap) ed.getMapLast();
        Set          esl       = eMapLast.entrySet();
        Iterator     b         = esl.iterator();
        Map.Entry    mel       = (Map.Entry) b.next();
        e = (Employee) mel.getValue();
        out.println(e.toString());
        out.print(eList.get(0));

        out.print("<a href=/>Go back to Homepage</a>");
        out.print("</BODY>");
        out.print("</HTML>");
        out.close();

    }

}