1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
@WebServlet("/inscription")
public class InscriptionServlet extends HttpServlet {
private static final long serialVersionUID = -8710385077137206045L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
forward("inscription.jsp", req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
Inscription inscription = new Inscription();
inscription.setLogin(req.getParameter("login"));
inscription.setEmail(req.getParameter("email"));
inscription.setConditionsGeneralesApprouvees(Boolean.parseBoolean(req.getParameter("conditionsGeneralesApprouvees")));
try {
inscription.validate();
req.setAttribute("inscription", inscription);
forward("inscriptionOk.jsp", req, resp);
} catch (InscriptionInvalideException e) {
req.setAttribute("errors", e.getErrorMessages());
forward("inscription.jsp", req, resp);
}
}
private void forward(String page, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
RequestDispatcher dispatcher = req.getServletContext().getRequestDispatcher("/WEB-INF/views/" + page);
dispatcher.forward(req, resp);
}
} |
Partager