01: package web.examples;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServlet;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: /**
11: * Servlet for accessing/updating the user profile page.
12: */
13: public class UserProfile extends HttpServlet {
14: protected void doGet(HttpServletRequest req, HttpServletResponse res)
15: throws ServletException, IOException {
16: doPost(req, res);
17: }
18:
19: @SuppressWarnings("unused")
20: protected void doPost(HttpServletRequest req,
21: HttpServletResponse res) throws ServletException,
22: IOException {
23: UserProfileForm form = new UserProfileForm();
24:
25: if (req.getParameter("submit") != null) {
26: // Validate form data
27: if (form.validate(req)) {
28: String fullName = form.getFullName().getValue();
29: String phone = form.getPhone().getValue();
30: int age = form.getAge().getValue();
31: char gender = form.getGender().getValue();
32:
33: // process data..
34: }
35: }
36:
37: req.setAttribute("form", form);
38: getServletContext().getRequestDispatcher("/UserProfile.jsp")
39: .forward(req, res);
40: }
41:
42: }
|