我想通过使用javascript代码调用Servlet doPost()方法,但是我得到了http 405(此URL不支持HTTP方法GET)异常。
这是我的javascript代码:
url="RedirectServlet?&FD="+FD+"&TD="+TD+"&actionid="+status+"&usercode="+usercode+"&action=reports"+"";
RedirectServlet.java:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if(action.equals("reports")){
System.out.println("inside reports");
//Getting values from Reports_arb.jsp
String Fromdate=request.getParameter("FD");
String Todate=request.getParameter("TD");
String status=request.getParameter("actionid");
String usercode=request.getParameter("usercode");
//placing given values in a session
request.setAttribute("FD", Fromdate);
request.setAttribute("TD", Todate);
request.setAttribute("actionid", status);
request.setAttribute("usercode", usercode);
//Redirecting to showReport_arb.jsp
//response.sendRedirect("showReport_arb.jsp");
request.getRequestDispatcher("showReport_arb.jsp").include(request, response);
}
}
答案 0 :(得分:1)
看到你URL
后,您sending
data along with the URL
。作为servlet
get
请求。
因此URL
正在尝试访问doGet
,但doGet
中servlet
没有实施导致问题。
修改强>
使用它来访问您的servlet doPost
<form ... method="post">...</form>