Servlet----------developing servlets through HttpServlet

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.