Java Reference
In-Depth Information
throws ServletException,
IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest
request, HttpServletResponse response)
throws ServletException,
IOException {
processRequest(request, response);
}
}
As you can see, our ConnexionServlet class extends javax.servlet.http.
HttpServlet ; this is an abstract class that implements the Servlet interface. It
defines the lifecycle methods ( doGet and doPost ) of the Servlet object that al-
lows us to handle HTTP service requests and send back a response. To access
the page generated by this Servlet, you must enter an URL similar to this one: ht-
tp://localhost:8080/chapter03PresentationLayer/connexionSer-
vlet . Here, connexionServlet is the name given in the @WebServlet annota-
tion. On this page, you will have the Sign it button displayed by using the following
instruction :
out.write(" <input type=\"submit\"
value=\"Sign it\"/>");
A click on this button generates an HTTP request that will cause execution of the
processRequest(HttpServletRequest request, HttpServletResponse
response) method. Based on the results of the connexion parameters validation,
you will be redirected to the error page or home page. In the case of a redirect to the
home page, we will add to the URL a parameter containing the name of the user in
order to adapt the greeting. The URL of the homepage is the following:
http://localhost:8080/chapter03PresentationLayer/WelcomeSer-
vlet?name=arnoldp
Search WWH ::




Custom Search