Java Reference
In-Depth Information
L ISTING 9.1
Continued
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Get the current session
HttpSession session = request.getSession(true);
// Get the id stored in the session after approval
String id = (String)session.getAttribute(“id”);
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<html>”);
out.println(“<head><title>Roll Your Own</title></head>”);
out.println(“<body>”);
out.println(“Hello “ + id + “ how can we help you today?”);
out.println(“</body></html>”);
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
9
// Get the id/password combination from the request
String id = request.getParameter(“id”);
String password = request.getParameter(“password”);
HttpSession session = null;
// Check to see if this is a valid id/password combination.
boolean valid = validateUser(id, password);
// If it is valid, get the session
// and add the id for future transactions
if ( valid == true ) {
session = request.getSession(true);
session.setAttribute(“id”, id);
 
Search WWH ::




Custom Search