在javascript中调用servlet doPost方法

时间:2013-05-31 04:00:47

标签: javascript servlets

我想通过使用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);

    }  
  }  

1 个答案:

答案 0 :(得分:1)

看到你URL后,您sending data along with the URL。作为servlet get请求。

因此URL正在尝试访问doGet,但doGetservlet没有实施导致问题。

修改

使用它来访问您的servlet doPost

<form ...   method="post">...</form>