whether the getRequestURL you posted above suits for my needs ?
No it doesn't. I interpreted your initial question differently.
I don't know if the Servlet API has a solution for this (except for the unreliable request.getHeader("referer") ) -- or "Referer", I'm not sure. . You could add the name of the form to the form's submit url: and retrieve that in your servlet (request.getParameter("myPage"))
[ May 09, 2007: Message edited by: Jan Cumps ] [ May 09, 2007: Message edited by: Jan Cumps ]
Joined: Jan 19, 2006
Thanks again Jan for your prompt reply.
I think your suggestion could be considered for sure.
Anyway, I solved my problem by using a filter which intercepts each user request and then tracks the url as a session attribute by using contextPath(), servletPath() and pathInfo() methods right before calling the doFilter method. This way I think it's more transparent for the web designer just because he/she doesn't need to bother on remembering to inform a request parameter on each posted url as you suggested above.
Anyway, thank you very much for your prompt suggestion.
5.4 Request Path Elements The request path that leads to a servlet servicing a request is composed of many important sections. The following elements are obtained from the request URI path and exposed via the request object: * Context Path: The path prefix associated with the ServletContext that this servlet is a part of. If this context is the "default" context rooted at the base of the web server's URL namespace, this path will be an empty string. Otherwise, this path starts with a '/' character but does not end with a '/' character. * Servlet Path: The path section that directly corresponds to the mapping which activated this request. This path starts with a '/' character. * PathInfo: The part of the request path that is not part of the Context Path or the Servlet Path.
Joined: Jan 19, 2006
At a first shot the answer seems yes. But think with me...
Once the filter is executed before the jsp call, then I can track the requested URL properly.
So, as I do not want filter calls to Servlets and I need just filter calls for JSP pages, when calling the Servlet thru save.do link, no filter will be fired and then the Servlet will be able to read the last accessed url tracked when the user requested the JSP page.
Dear Edisandro, I too have the same problem what you have faced getting requesting page URL in the servlet. I cant understand your solution. So can you send me sample code snippet to understand it better.