HTTP method POST is not supported by this URL
HTTP Status 405 - HTTP method POST is not supported by this URL
寫一個(gè)Servlet頁(yè)面跳轉(zhuǎn)時(shí),出現(xiàn)了HTTP Status 405 - HTTP method POST is not supported by this URL 這個(gè)錯(cuò)誤。
我的servlet的跳轉(zhuǎn)代碼如下:
request.getRequestDispatcher("FindByIdServlet?id="+commentPostId).forward(request, response);
在Servlet中使用這種方式跳轉(zhuǎn)到另一個(gè)Servlet時(shí)就會(huì)出現(xiàn)如題的錯(cuò)誤,改用sendRedirect(),即可解決此問題了:
response.sendRedirect("FindByIdServlet?id="+commentPostId);
redirect和forward的區(qū)別:
1) redirect 方式
response.sendRedirect("test.jsp");
頁(yè)面的路徑是相對(duì)路徑。sendRedirect可以將頁(yè)面跳轉(zhuǎn)到任何頁(yè)面,不一定局限于本web應(yīng)用中,如:
response.sendRedirect("http://www.baidu.com";);
跳轉(zhuǎn)后瀏覽器地址欄變化,會(huì)變成你跳轉(zhuǎn)到的頁(yè)面的地址。
這種方式要傳值出去的話,只能在url中帶parameter或者放在session中,無(wú)法使用request.setAttribute來(lái)傳遞。
2) forward方式
RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
頁(yè)面的路徑是相對(duì)路徑。forward方式只能跳轉(zhuǎn)到本web應(yīng)用中的頁(yè)面上。
跳轉(zhuǎn)后瀏覽器地址欄不會(huì)變化。
使用這種方式跳轉(zhuǎn),傳值可以使用三種方法:url中帶parameter,session,request.setAttribute
來(lái)源: http://www.programbbs.com/bbs/view23-14330-1.htm
posted on 2009-02-15 18:50 YXY 閱讀(4282) 評(píng)論(0) 編輯 收藏