解决HTTP Status 405 - HTTP method POST is not supported by this URL 详解方案
2015-03-27 14:15
651 查看
报这个错误提示有两方面问题:
1、在servlet中没有调用post()方法引起的
2、在serlvet中跳转没有用外跳(response.sendRedirect())
我在做项目时,遇到的是1的错误,在servlet中没有调用post().我在jsp页面中提交一个XMLHTTPRequest请求到servlet时,在相应的Servlet中没用到post(),因此报这个错误。解决方案:
在Servlet中调用这个方法就行了。
对于遇到2的错误的朋友,可以采用以下解决方案:
把request.getRequestDispatcher("FindByIdServlet?id="+commentPostId).forward(request, response);
改成response.sendRedirect("FindByIdServlet?id="+commentPostId);
redirect和forward的区别:
1) redirect 方式
response.sendRedirect("test.jsp");
页面的路径是相对路径。sendRedirect可以将页面跳转到任何页面,不一定局限于本web应用中,如:
response.sendRedirect("http://www.baidu.com");
跳转后浏览器地址栏变化,会变成你跳转到的页面的地址。
这种方式要传值出去的话,只能在url中带parameter或者放在session中,无法使用request.setAttribute来传递。
2) forward方式
RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
页面的路径是相对路径。forward方式只能跳转到本web应用中的页面上。
跳转后浏览器地址栏不会变化。
使用这种方式跳转,传值可以使用三种方法:url中带parameter,session,request.setAttribute
1、在servlet中没有调用post()方法引起的
2、在serlvet中跳转没有用外跳(response.sendRedirect())
我在做项目时,遇到的是1的错误,在servlet中没有调用post().我在jsp页面中提交一个XMLHTTPRequest请求到servlet时,在相应的Servlet中没用到post(),因此报这个错误。解决方案:
在Servlet中调用这个方法就行了。
对于遇到2的错误的朋友,可以采用以下解决方案:
把request.getRequestDispatcher("FindByIdServlet?id="+commentPostId).forward(request, response);
改成response.sendRedirect("FindByIdServlet?id="+commentPostId);
redirect和forward的区别:
1) redirect 方式
response.sendRedirect("test.jsp");
页面的路径是相对路径。sendRedirect可以将页面跳转到任何页面,不一定局限于本web应用中,如:
response.sendRedirect("http://www.baidu.com");
跳转后浏览器地址栏变化,会变成你跳转到的页面的地址。
这种方式要传值出去的话,只能在url中带parameter或者放在session中,无法使用request.setAttribute来传递。
2) forward方式
RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
页面的路径是相对路径。forward方式只能跳转到本web应用中的页面上。
跳转后浏览器地址栏不会变化。
使用这种方式跳转,传值可以使用三种方法:url中带parameter,session,request.setAttribute
相关文章推荐
- 解决HTTP Status 405 - HTTP method POST is not supported by this URL 详解方案
- 关于解决HTTP Status 405 - HTTP method POST is not supported by this URL方法之一
- HTTP Status 405 - HTTP method POST is not supported by this URL
- (6) HTTP Status 405 - HTTP method POST is not supported by this URL
- 出现HTTP Status 405 - HTTP method GET is not supported by this URL 原因及解决方法:
- HTTP Status 405 - HTTP method POST is not supported by this URL
- HTTP Status 405 - HTTP method GET(POST) is not supported by this URL
- HTTP Status 405 - HTTP method POST is not supported by this URL
- 访问arcgisserver报:HTTP Status 405 - HTTP method GET is not supported by this URL
- servlet错误:HTTP Status 405 - HTTP method GET is not supported by this URL
- servlet错误:HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP Status 405 - HTTP method POST is not supported by this URL
- HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP Status 405 - HTTP method GET is not supported by this URL
- 出现HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP Status 405 - HTTP method POST/GET is not supported by this URLyi
- 关于Servlet报错:405 HTTP method GET is not supported by this URL问题解决方法
- HTTP Status 405 - HTTP method GET is not supported by this URL
- HTTP Status 405 -- HTTP method POST is not supported by this URL