| Author |
RequestDispatcher.forward() - reload/refresh page link? / how to get original URL?
|
James Hodgkiss
Ranch Hand
Joined: Jan 22, 2004
Posts: 401
|
|
My servlets (Servlet1, Servlet2, etc.) use RequestDispatchers so they may forward their requests to ErrorServlet.
In ErrorServlet, I want to output a 'Retry' link, that provides a link to the original servlet (Servlet1 or Servlet2, etc.), but how do I obtain the href value of the original servlet for such link.
I've tried request.getRequestURL() but it gives the ErrorServlet url, so how would I get the original Servlet1/Servlet2/etc url from within ErrorServlet? (Is the only way to add the url as a session attribute or is there some simpler way?)
I need to achieve this without resorting to javascript.
Many thanks,
James
|
 |
Monika Joshi
Greenhorn
Joined: Apr 19, 2010
Posts: 9
|
|
Hi James,
In the servlet, that does the forwarding to the ErrorServlet, set a request attribute which keeps the original path i.e request.setAttribute("OriginalScreenPath", request.setServletPath()); and then get the request dispatcher and forward to ErrorServlet.Now in the ErrorServlet, request is coming in as parameter.This request will contain not only the original request parameters, but also the path to Original servlet("OriginalScreenPath") that you set before forwarding the request. This you can now use when you generate the response and with Retry link.
Cheers,
Minakshi
|
 |
James Hodgkiss
Ranch Hand
Joined: Jan 22, 2004
Posts: 401
|
|
Many thanks for your reply. So, to recreate the original link with params, I'd use it like this?...
String originalScreenPath = (String)request.getAttribute("originalScreenPath");
String params = request.getQueryString();
String href = originalScreenPath + "?" + params;
Cheers,
James
|
 |
 |
|
|
subject: RequestDispatcher.forward() - reload/refresh page link? / how to get original URL?
|
|
|