package java112.project4; import java.util.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java112.employee.*; /** * This is the first Servlet for project 2, displaying an image and link back * to the home page. * *@author SRasmussen *@created October 11, 2006 */ public class AppInitServlet extends HttpServlet { private Properties properties = new Properties(); private ServletConfig config; private ServletContext context; /** * This initialization method calls a method to load the properties object. * *@exception ServletException Description of the Exception Like a * constructor, but no constructors in servlets. */ public void init() throws ServletException { config = getServletConfig(); context = config.getServletContext(); loadProperties(); context.setAttribute("props", properties); java112.employee.EmployeeDirectory empDir = new java112.employee.EmployeeDirectory(); empDir.createEmployeesCollection(properties.getProperty("input.file")); context.setAttribute("directory", empDir); } /** * Description of the Method * *@param req 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 req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); // set the response type before sending data PrintWriter out = res.getWriter(); out.print(""); out.print(""); out.print(properties.getProperty("author.name")); out.print("'s Application Initialization Servlet"); out.print(""); out.print("

"); out.print(properties.getProperty("author.name")); out.print("'s Applicaiton Initialization Servlet



"); out.print(context.getAttribute("props")); out.print(context.getAttribute("directory")); out.write("\"Desert
"); out.write("
home page
"); out.print(""); out.print(""); out.close(); } /** * This method loads the properties object with those key/value pairs found * on the input properties file. */ public void loadProperties() { try { properties.load(this.getClass().getResourceAsStream("/project4.properties")); } catch (IOException ioe) { System.out.println("Can't load the properties file"); ioe.printStackTrace(); } catch (Exception e) { System.out.println("Problem: " + e); e.printStackTrace(); } } }