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

// DetailUpdateServlet.java
// This servlet receives the contents of the addressData form via HTTP/POST.
// That data is then compared to the data within the AddressDataBean stored
// in the session environment. The fields that have been changed are then
// tagged for update. A sql update statement is then formulated from the tagged
// data fields.
package com.bullseyecomputing.servlets;
import java.io.*;
import java.util.*;
import java.sql.*;
import jacax.servlet.*;
import javax.servlet.http.*;
import com.bullseyecomputing.beans.AddressDataBean;
public class DetailUpdateServlet extends HttpServlet {
ServletContext context;
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Grab a handle to the local context
context = getServletContext();
// Get the jdbc driver name from an init param
String jdbcDriver = getInitParameter("jdbcDriver:);
// Attempt to load the jdbc driver
try {
Class.forName(jdbcDriver);
}
catch(ClassNotFoundException e) {
context.log("jdbcDriver: ", e);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession(false):
ConnectionListener dbListener;
Statement transaction;
RequestDispatcher dispatcher;
// Bail if this is not an existing session
if(session == null) {
dispatcher = request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
}
// get POST parameters
//////////
// Check the session environ for an existing db connection
///////////
dbListener = (ConnectionListener) session.getAttribute("dbConnection");
if(dbListener == null) {
String jdbcURL = getInitParameter("jdbcURL");
String jdbcUser = getInitParameter("jdbcUser");
String jdbcPassword = getInitParameter("jdbcPassword");
try {
Connection conn = DriverManager.getConnection(jdbcURL,jdbcUser,jdbcPassword);
dbListener = new ConnectionListener(conn);
session.setAttribute("dbConnection:, dbListener);
}
catch(SQLException e) {
context.log("dbConnection: ", e);
}
}
// Grab a local handle to the connection
Connection db = dbListener.getConnection();