This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
When your servlet's doGet(), doPost(), ... method is called, you get a parameter of type HttpServletRequest.
One of it's methods, getRequestURL() profides this functionality: Reconstructs the URL the client used to make the request.
Regards, Jan
OCUP UML fundamental
ITIL foundation
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
posted
0
Thank you very much for your prompt reply.
Let me clear some more my doubt :
First : Supposing my jsp page located at http://MyApp/product/showDetails.jsp have a button which calls the servlet named UpdateProduct mapped to url /product/save.do
Second : From within that servlet I would like to know some method that returns the URL that made the servlet call, in this case, the url /product/showDetails.jsp
I know there are some methods in the request such as getServletPath, getQueryString and so on ... but by using these methods I get the url /product/save.do which is not what I want.
Dear Jan,
Cany you confirm whether the getRequestURL you posted above suits for my needs ?
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"))
Regards, Jan
[ May 09, 2007: Message edited by: Jan Cumps ] [ May 09, 2007: Message edited by: Jan Cumps ]
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
posted
0
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.
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
posted
0
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.
Thanks in Advance.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How to get the servlet's requesting page ?