HTTP Status 405 - HTTP method POST is not supported by this URL

删除回忆录丶 提交于 2019-11-30 15:34:20

(sorry about the wrong answer I posted before, I deleted it).


Apparently the URL /EditObject is mapped on another servlet which doesn't have doPost() method overriden. It would be called on RequestDispatcher#forward() as well because the method of currently running HTTP request is POST. The default HttpServlet#doPost() implementation will return HTTP 405. If your actual intent is to fire a GET request on it so that the doGet() method will be invoked, then you should rather use HttpServletResponse#sendRedirect() instead.

response.sendRedirect("/EditObject?id="+objId);

Add a doPost() to your EditObject class:

 @SuppressWarnings("serial")
public class EditObject extends HttpServlet{

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
      process(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
      process(request, response);
    }


    public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {    
        int objId = Integer.parseInt(request.getParameter("id"));
        dispPage(objId, request, response);
    }

    private void dispPage(int objId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{        

// ... lots of code in here
            getServletContext().getRequestDispatcher("/jsp/objectPageEdit.jsp").forward(request, response);

    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!