import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.security.*; public class WorkerServlet extends HttpServlet { private Connection dbConnection; public void init() { dbConnection = DBInfo.connectToDatabase(); } public void destroy() { if(dbConnection != null) { try { dbConnection.close(); } catch(Exception e) { } } } synchronized private boolean recordWork(String name, String activity, double hours) { try { Statement stmt = dbConnection.createStatement (); String insertcommand = "insert into Work values ("; insertcommand = insertcommand + "'" + name + "', "; insertcommand = insertcommand + "'" + activity + "', "; insertcommand = insertcommand + hours + ")"; stmt.executeUpdate(insertcommand); stmt.close(); } catch(Exception e) { return false; } return true; } public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String activity = request.getParameter("Activity"); String time = request.getParameter("Hours"); if((activity==null) || (time==null)) { response.sendRedirect("/combo/BadData.html"); return; } double dtime = 0.0; try { dtime = Double.parseDouble(time); } catch(Exception e) { response.sendRedirect("/combo/BadData.html"); return; } String name = request.getRemoteUser(); if(!recordWork(name, activity, dtime)) { response.sendRedirect("/combo/NoDB.html"); return; } PrintWriter out = response.getWriter(); out.println("