GeeCON Prague 2014*
The moose likes Servlets and the fly likes getting the URL for the calling jsp page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "getting the URL for the calling jsp page?" Watch "getting the URL for the calling jsp page?" New topic
Author

getting the URL for the calling jsp page?

Tom Barns
Ranch Hand

Joined: Oct 27, 2000
Posts: 138
Hi all
if i have a jsp page(caller.jsp) that has one or two textfield,one for id and the other for password.
if i want to make that jsp call a response.jsp,that response.jsp just catches those parameters (id and pass).
if somewhere in my response.jsp i want to get the url for the caller jsp(in our case it is caller.jsp) how can i get it?
here is the code for caller.jsp and response.jsp
code: caller.jsp
//--------------
<html>
<form action="/examples/jsp/response.jsp" >
id <input type="text" name="id" >
pass <input type="text" name="password" >
</form>
</html>
//---------------
response.jsp:
//----------
id is <%=request.getParameter("id")%>
pass is <%=request.getParameter("password")%>
//i need here code to display the full URL for the caller.jsp
//-----------


Thanks for your help.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Tom,
Please refer to this thread. response.getHeader("referrer"); will help you I think.
http://www.javaranch.com/ubb/Forum7/HTML/002263.html
regds
maha anna
Tom Barns
Ranch Hand

Joined: Oct 27, 2000
Posts: 138
Thanks alot.
Tom Barns
Ranch Hand

Joined: Oct 27, 2000
Posts: 138
Thanks for your earlier help.i have another question which is:
if i have a url as:http://localhost:8080/examples/jsp/lloTest/login2.jsp?users=3
i need to catch it in the calling page(the next page) as it is completly with the parameters(as for example with users=3)
because when i use the method request.getHeader("refere")
if i use post method i got the url without parameter.
but when i type in the browser as: http://localhost:8080/examples/jsp/lloTest/login2.jsp?users=3
and i hit enter i got <%=request.getHeader("referer")%> gives null.
finally please i need an idea how to get the previous url with its parameters.
thanks
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Tom,
I am unable to understand your post cleary. Can you rephrase it.
Assume there are 2 jsps first.jsp and second.jsp.

<%= request.getHeader("referer") means the complete URL with which you invoked the first.jsp. Which means whatever appreared on the browser address bar to invoke first.jsp will be caught in second.jsp.
//case 1
Assume you invoked first.jsp from browser as http://localhost/MISApp/Login/first.jsp?users=100 , and in your first.jsp you used method=post inside <form> to invoke second.jsp then we will get the WHOLE http://localhost/MISApp/Login/first.jsp?users=100 for request.getHeader("referer").
//case 2
On the other hand if you would have used http://localhost/MISApp/Login/first.jsp to invoke first.jsp you will get same http://localhost/MISApp/Login/first.jsp
in second.jsp
//case 3
If you would have method=post from zero.jsp (which calls first.jsp and zero.jsp had some values users=100) to invoke first.jsp itself, all those users=100 values will not be appended to browser's address bar since method=post is used. So in second.jsp we can't get those users=100 portion as part of referer URL.
Bottom line whatever appeared in browser's address bar to invoke first.jsp ONLY will be known as 'referer' string at second.jsp.
I am still not sure if I understood your problem exactly as you have in mind.
Regarding your 'null' value, if we directly invoke second.jsp as http://localhost/MISApp/Login/second.jsp we will get 'referer' value as null because there is no prior URL which is calling this second.jsp. Isn't? We deleted (cleaned) everything in the browser address bar and started afresh. So there is no prior page which is actually calling this second.jsp, because it is us(human) who is really calling. I just assume this could be your case
Please reply so that we can continue.

regds
maha anna

[This message has been edited by maha anna (edited April 13, 2001).]
Tom Barns
Ranch Hand

Joined: Oct 27, 2000
Posts: 138
Thanks alot,it was a great help.
that helped me to get it fixed.
thanks.
 
GeeCON Prague 2014
 
subject: getting the URL for the calling jsp page?