码迷,mamicode.com
首页 > Web开发 > 详细

【HttpServlet】HttpServlet类

时间:2019-07-17 16:58:22      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:jpg   技术   ima   str   时间   直接   https   tps   height   

创建时间:6.15

 

HttpServlet

 

但在实际开发中,我们不会直接去实现Servlet接口,因为那样需要覆盖的方法太多,    我们一般创建类继承HttpServlet

实现步骤:

1)创建类继承HttpServlet类

 

 技术图片

 

 

*注意:由于注解注释配置servlet,所以已经不需要在web.xml中配置

 技术图片

 

2)覆盖doGet和doPost

*不用写service(ServletRequest req, ServletResponse res)方法,因为HttpServlet接口里实现了;service(ServletRequest req, ServletResponse res)调用service(HttpServletRequest req, HttpServletResponse res)方法,后者再调用doGet()或doPost()方法,所以我们重写这两个方法就行。

 

/*3)在web.xml中进行servlet的配置*/  servlet2.5及以后不需要了

 

 

(1)HttpServlet类的方法

1)init()

2)doGet(HttpServletRequest request,HttpServletResponse response)

3)doPost(HttpServletRequest request,HttpServletResponse response)

4)destroy()

 技术图片

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

【HttpServlet】HttpServlet类

标签:jpg   技术   ima   str   时间   直接   https   tps   height   

原文地址:https://www.cnblogs.com/musecho/p/11201824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!