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?)
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.
Joined: Jan 22, 2004
Many thanks for your reply. So, to recreate the original link with params, I'd use it like this?...