0

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

    }  
  }  
vagga ravi
  • 43
  • 1
  • 2
  • 11
  • It seems you are making a GET request, which the server doesn't accept. It seems to accept POST only, hence its name – Ian May 31 '13 at 04:02
  • by default, your request is GET and servlet does not accept GET. I think you should change to POST in the request header. – Phong Vo May 31 '13 at 04:06
  • @Ian Thanks for your immediate reply.How do we make a post request to servlet from javascript – vagga ravi May 31 '13 at 04:07
  • See, [How to use Servlets and Ajax?](http://stackoverflow.com/a/4113258/1037210) and you'll never have to scratch your head from soon onwards, I'm pretty sure. – Lion May 31 '13 at 04:08

1 Answers1

1

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>
NPKR
  • 5,368
  • 4
  • 31
  • 48
  • i want to hide the url data in the redirect jsp(above showreports_arb.jsp) thats why i used doPost() method in my servlet – vagga ravi May 31 '13 at 04:14