Reputation:
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");
}
Upvotes: 1
Views: 153
Reputation: 2056
Do not use redirect
Use:
RequestDispatcher rd= request.getRequestDispatcher(url);
rd.forward(request, response);
Upvotes: 1