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 {
       
    }

你可能感兴趣的:(HttpServlet中的doGet和doPost方法)