1

I have created a project just to see how dispatch works in servlet to send response back to jsp after getting request from another jsp. But the problem is jsp sends the request pretty well and when its time for servlet to response, i get some kind of 404 error and everything stops.

Here is my code in post method:

protected void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    request.setAttribute("key", "Any message can be stored.");

    out.println("Mansoor");
    out.println(request.getParameter("operation"));

    String url = "/" + request.getParameter("operation") + ".jsp";
    System.out.println(url);

    //response.sendRedirect(url);
    response.sendRedirect("url");
}
Peter Keller
  • 6,746
  • 2
  • 20
  • 23

1 Answers1

1

Do not use redirect

Use:

RequestDispatcher rd= request.getRequestDispatcher(url);
rd.forward(request, response);
Mansoor Akram
  • 1,778
  • 3
  • 21
  • 36
  • @D3T0NAT0R Also read [this](http://stackoverflow.com/questions/2047122/requestdispatcher-interface-vs-sendredirect) might help you .. – Santhosh Mar 21 '14 at 08:34