×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Pascal Surget
Added: Sep 6, 2018 12:52 PM
Views: 3319
Tags: no tags
  1. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  2.                 //on recupere la la date de naissance
  3.                 String birthday = request.getParameter("birthday");
  4.                
  5.                 //on calcule l'age
  6.                 try {
  7.                         //on convertit une string en Date
  8.                         SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
  9.                         Date date = formatter.parse(birthday);
  10.                         //annee courante - annee de naissance
  11.                         int age = getAge(date);
  12.                         request.setAttribute("age", age);
  13.                         //on delegue l'affichage à une JSP
  14.                         RequestDispatcher rd = request.getRequestDispatcher("Ex1Affichage.jsp");
  15.                         rd.forward(request, response);
  16.                        
  17.                 } catch (ParseException e) {
  18.                         // TODO Auto-generated catch block
  19.                         e.printStackTrace();
  20.                 }
  21.                
  22.                
  23.         }