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

前端 未结 2 1465
终归单人心
终归单人心 2021-01-03 08:06

I am getting the error HTTP Status 405 - HTTP method POST is not supported by this URL when I use the following code(below) ... the line causing the trouble (ap

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 08:43

    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);
    
        }
    }
    

提交回复
热议问题