This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes RequestDispatcher.forward() - reload/refresh page link? / how to get original URL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher.forward() - reload/refresh page link? / how to get original URL?" Watch "RequestDispatcher.forward() - reload/refresh page link? / how to get original URL?" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher.forward() - reload/refresh page link? / how to get original URL?
 
Similar Threads
servlet to servlet communication
whats the difference between forward and redirect?
Inter-Servlet Communication
Form Variables
how to check value initialisation between two servlets