【HttpServlet】HttpServlet类

Created: 6.15

 

HttpServlet

 

But in the actual development, we will not go directly to implement the Servlet interface, because too many methods that need to be covered, we generally create a class inherited HttpServlet

Implementation steps:

1) create a class inherited HttpServlet class

 

 

 

 

* Note: Because the notes comments configuration servlet, so you do not need to configure in web.xml

 

 

2) covering and doPost doGet

* Do not write service (ServletRequest req, ServletResponse res) method, because the interface in HttpServlet implements; service (ServletRequest req, ServletResponse res) call service (HttpServletRequest req, HttpServletResponse res) method, which then calls the doGet () or doPost () method, so we rewrite these two methods on the line.

 

/ * 3) servlet configuration in web.xml * / Servlet2.5 not necessary and after

 

 

Method (1) HttpServlet class

1)init()

2)doGet(HttpServletRequest request,HttpServletResponse response)

3)doPost(HttpServletRequest request,HttpServletResponse response)

4)destroy()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/musecho/p/11201824.html