01: package web.examples;
02:
03: import java.io.IOException;
04: import java.util.Date;
05:
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServlet;
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: public class CreditCardApp extends HttpServlet {
12: protected void doGet(HttpServletRequest req, HttpServletResponse res)
13: throws ServletException, IOException {
14: doPost(req, res);
15: }
16:
17: @SuppressWarnings("unused")
18: protected void doPost(HttpServletRequest req,
19: HttpServletResponse res) throws ServletException,
20: IOException {
21: CreditCardAppForm form = new CreditCardAppForm(req);
22:
23: if (req.getParameter("submit") != null) {
24: if (form.validate(req)) {
25: // Grab values from the form
26: String firstName = form.getFirstName().getValue();
27: String lastName = form.getLastName().getValue();
28: Date dob = form.getDob().getValue();
29: Boolean isCustomer = form.getHasAccountWithUs()
30: .getValue();
31:
32: //
33: // Note that input values can also be accessed directly
34: // using the form.getInputValue("xxx") method.
35: //
36:
37: String email = form.getInputValue("email");
38: EmploymentStatus status = form
39: .getInputValue("employmentStatus");
40: Integer monthlyIncome = form
41: .getInputValue("monthlyIncome");
42:
43: // etc...
44: }
45: }
46:
47: req.setAttribute("form", form);
48: getServletContext().getRequestDispatcher("/CreditCardApp.jsp")
49: .forward(req, res);
50: }
51:
52: }
|