现在的位置: 首页 > 综合 > 正文

Servlet中doGet(),doPost(),service()函数的关系(转载)

2013年03月09日 ⁄ 综合 ⁄ 共 465字 ⁄ 字号 评论关闭

转载自 http://blog.cafemood.net/sgr/post/6.html

 

 

1,三者之间的关系:doGet()和doPost()是由函数service()调用才执行的。也就是说,当从HttpServlet类继承时可以绕过doGet()和doPost()直接override service()函数,也可以override doGet()和doPost()

 

2,service() 该函数使用起来不像duPost()与duGet()那样有约束,但几乎失去了HttpServlet的意义。很类似于GeneratServlet

 

3,doGet() 超链接或直接在浏览器地址栏访问时起作用

 

4,doPost() form提交时起作用

 

如果两者均有,则可用service() 或者

protected void doGet(HttpServletRequest rst, HttpServletResponse resp) throws ServletException , java.io.IOException {

    doPost(req,resp);

}

抱歉!评论已关闭.