使用HttpServlet的三种方式

来源:互联网 发布:携程程序员怒删数据库 编辑:程序博客网 时间:2024/06/03 19:07

使用HttpServlet的三种方式

/** *   使用HttpServlet的三种方式 *   1、在get里面调用post *   2、在post里面调用get *   3、不管什么请求(post或get)。直接在service中执行就可以了 *  * */public class TestHttpServlet extends HttpServlet{/** *  */private static final long serialVersionUID = 1L;//1、在get里面调用post@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//this.doPost(req, resp);System.out.println("post里面调用get。。。。");}//2、在post里面调用get@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//System.out.println("get里面调用post。。。。");this.doGet(req, resp);}// 3、不管什么请求(post或get)。直接在service中执行就可以了@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// TODO Auto-generated method stubSystem.out.println("随便什么请求");}}

第三种(推荐):不管什么请求,直接在service中执行就可以了