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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author amar
* @version
*/
public class index extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String age ="";
long Age=0;
response.setContentType("text/html;charset=UTF-8");
PrintWriter page = response.getWriter();
page.println("<html>");
page.println("<head>");
page.println("<title>Ma première Servlet</title>");
page.println("</head>");
page.println("<body>");
page.println("<center><h1>Ma première servlet<h1></center>");
page.println("<form action =\"http://localhost:8084//index\" method=\"post\">");
page.println("Votre age : <input type=\"text\" size=\"5\" name=\"age\">");
page.println("<input type=\"submit\" value=\"Ok\"> </from>");
try{
age = request.getParameter("age");
Age = Long.parseLong(age);
}
catch(Exception e){
System.out.println("Erreur de construction: "+e.getMessage());
}
page.println("<div style=\"border-style:solid; width:150px; height:150px; \">"+Age+"</div>");
page.println("</body>");
page.println("</html>");
// page.close();
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}
class IntException extends Exception{
public IntException (String mes){
super(mes);
}
} |
Partager