码迷,mamicode.com
首页 > 其他好文 > 详细

自定义servlet重写doGet或者doPost方法时,405 method not allowed

时间:2018-12-13 16:32:02      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:toc   over   ...   cte   自定义   test   support   protocol   删掉   

自定义servlet

public class TestServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		super.doGet(req, resp);
		
	}
}

HttpServlet里的doGet方法是这样定义的

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        String protocol = req.getProtocol();
        String msg = lStrings.getString("http.method_get_not_supported");
        if (protocol.endsWith("1.1")) {
            resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
        } else {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
        }
    }

所以重写doGet/doPost方法时,必须先将super.doGet(...)/super.doPost(...)删掉

自定义servlet重写doGet或者doPost方法时,405 method not allowed

标签:toc   over   ...   cte   自定义   test   support   protocol   删掉   

原文地址:https://www.cnblogs.com/qf123/p/10114012.html

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