[英]Calling servlet doPost method in the javascript
I want to call Servlet doPost() method by using the javascript code but iam getting http 405(HTTP method GET is not supported by this URL) exception. 我想通过使用javascript代码来调用Servlet doPost()方法,但是我正在获取http 405(此URL不支持HTTP方法GET)。
Here is my javascript code: 这是我的JavaScript代码:
url="RedirectServlet?&FD="+FD+"&TD="+TD+"&actionid="+status+"&usercode="+usercode+"&action=reports"+"";
RedirectServlet.java: 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);
}
}
By seeing you URL
, you are sending
the data along with the URL
. 通过查看
URL
,您可以sending
data along with the URL
sending
。 which as servlet
get
request. 它作为
servlet
get
请求。
So URL
is trying access doGet
, but where there is no implemention of doGet
in servlet
causing problem. 因此,
URL
尝试访问doGet
,但是在servlet
没有实现doGet
情况下会导致问题。
EDIT 编辑
use this to make access of your servlet doPost
使用它来访问您的servlet
doPost
<form ... method="post">...</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.