By inheriting HttpServlet abstract classes, the functionality is more powerful.
developing servlets through the HttpServlet method requires rewriting the Doget and doPost methods. This is one of the most used methods available.
such as: Class Myhttpservlet extends HttpServlet
1 PackageCn.servlet;2 3 Importjava.io.IOException;4 ImportJava.io.PrintWriter;5 6 Importjavax.servlet.ServletException;7 ImportJavax.servlet.http.HttpServlet;8 Importjavax.servlet.http.HttpServletRequest;9 ImportJavax.servlet.http.HttpServletResponse;Ten One Public classMyhttpservletextendsHttpServlet { A //in HttpServlet, the designer handles post submission and get submissions separately - //<form action= "submitted to? "Method=" Post|get ", default is Get commit - //In fact, Doget and Dopost eventually call the service () method in the Servlet interface the Public voiddoget (httpservletrequest request, httpservletresponse response) - throwsservletexception, IOException { - -PrintWriter out =Response.getwriter (); +Out.print ("); - } + A at Public voidDoPost (httpservletrequest request, httpservletresponse response) - throwsservletexception, IOException { -PrintWriter out =Response.getwriter (); -Out.print ("); - } -}
Deployment:
<Serlvet> <Servlet-name>Myhttpservlet</Servlet-name> <Servlet-class>Cn.servlet.MyHttpServlet</Servlet-class> </servlet> <servlet-mapping> <Servlet-name>Myhttpservlet</Servlet-name> <Url-pattern>/servlet/myhttpservlet</Url-pattern> </servlet-mapping>
The result is that the Doget method is called by default ,,,, and the get method displays the user name and password in the Address bar when the form is present, and the post method does not.
Servlet----------developing servlets through HttpServlet