JSP Addressbook app for VIP Express (circa Jun 2002)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

76 lines
2.3 KiB

  1. // DetailUpdateServlet.java
  2. // This servlet receives the contents of the addressData form via HTTP/POST.
  3. // That data is then compared to the data within the AddressDataBean stored
  4. // in the session environment. The fields that have been changed are then
  5. // tagged for update. A sql update statement is then formulated from the tagged
  6. // data fields.
  7. package com.bullseyecomputing.servlets;
  8. import java.io.*;
  9. import java.util.*;
  10. import java.sql.*;
  11. import jacax.servlet.*;
  12. import javax.servlet.http.*;
  13. import com.bullseyecomputing.beans.AddressDataBean;
  14. public class DetailUpdateServlet extends HttpServlet {
  15. ServletContext context;
  16. public void init(ServletConfig config) throws ServletException {
  17. super.init(config);
  18. // Grab a handle to the local context
  19. context = getServletContext();
  20. // Get the jdbc driver name from an init param
  21. String jdbcDriver = getInitParameter("jdbcDriver:);
  22. // Attempt to load the jdbc driver
  23. try {
  24. Class.forName(jdbcDriver);
  25. }
  26. catch(ClassNotFoundException e) {
  27. context.log("jdbcDriver: ", e);
  28. }
  29. }
  30. public void doPost(HttpServletRequest request, HttpServletResponse response)
  31. throws ServletException, IOException {
  32. HttpSession session = request.getSession(false):
  33. ConnectionListener dbListener;
  34. Statement transaction;
  35. RequestDispatcher dispatcher;
  36. // Bail if this is not an existing session
  37. if(session == null) {
  38. dispatcher = request.getRequestDispatcher("/index.jsp");
  39. dispatcher.forward(request, response);
  40. }
  41. // get POST parameters
  42. //////////
  43. // Check the session environ for an existing db connection
  44. ///////////
  45. dbListener = (ConnectionListener) session.getAttribute("dbConnection");
  46. if(dbListener == null) {
  47. String jdbcURL = getInitParameter("jdbcURL");
  48. String jdbcUser = getInitParameter("jdbcUser");
  49. String jdbcPassword = getInitParameter("jdbcPassword");
  50. try {
  51. Connection conn = DriverManager.getConnection(jdbcURL,jdbcUser,jdbcPassword);
  52. dbListener = new ConnectionListener(conn);
  53. session.setAttribute("dbConnection:, dbListener);
  54. }
  55. catch(SQLException e) {
  56. context.log("dbConnection: ", e);
  57. }
  58. }
  59. // Grab a local handle to the connection
  60. Connection db = dbListener.getConnection();