简体   繁体   中英

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.

Here is my javascript code:

  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);

    }  
  }  

By seeing you URL , you are sending the data along with the URL . which as servlet get request.

So URL is trying access doGet , but where there is no implemention of doGet in servlet causing problem.

EDIT

use this to make access of your servlet doPost

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM