I have a main JSP and process JSP. In process jsp I am committing the response and forward the response to a success page.
request.getRequestDispatcher("success.jsp").forward(request, response);
I am able to commit the response at the server side. Process jsp is also able to forward the response to success JSP.
But the url shows for example: http://process.jsp?param1=value1&parm2=value2
I want my output to display a clean as in url http://success.jsp
Please Note: This works perfectly fine for Java Servlet, i just tried it.
I am using only JSP instead of Java servelet, since this is our project requirement.
Can anyone suggest me a solution for this?
RequestDispatcher#forward()Is supposed to forward both the request and the response objects to another resource within the server. No response goes back to the client when you do aforward()and this is why the client shows the same initial URL.For the client to show another URL you could use
HttpServletResponse#sendRedirect(). This does go back to the client making it do a new request to the URL you want. So change it to:Remember not to commit the response before doing this or you’ll get an
IllegalStateExceptionAs to why you say that on a Servlet works, I’m not sure why, but is not how
forward()is supposed to work, and JSP are compiled to Servlets so in the end they should behave the same.