HttpServlet中的doGet和doPost方法


在web3.0中已解决get请求中午乱码问题,doGet和doPost方法可以这样写:

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }


如果要区分post和get请求的处理,doGet和doPost方法可以这样写:

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if("get".equalsIgnoreCase(req.getMethod())){
            //get请求
        }else {
            //post请求
        }

    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       
    }

猜你喜欢

转载自blog.csdn.net/city__chen/article/details/80760819