• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting the url of original page

 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

i have say for example my index.jsp which has a link to target.jsp and just uses the href tag in html
i want to get the url of index.jsp or the 1st page which calls the second page.
request.getRequestURI() returns target.jsp instead of index.jsp.
what am i doing wrong?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the API of HttpServletRequest. You will see following method.



getHeader("referer") will return your desired value.
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm sorry but i do not understand
what do you mean by referer?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Referer" is a header set in the request. It tells you from which page you came from.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36

But be careful, this is not a reliable way to get the page you came from.
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh ok
so in target.jsp i say,
String prev_url = request.getHeader("index.jsp");
is this it?

but the problem is, i want to know the referer
for example, i want to know the url of the page who clicked target.jsp.
so i may not always know the referer

thanks for the reply so far
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String prev_url = request.getHeader("Referer");

I insist that this is not recommended.
I don't think that there's a good simple way to get the referer.
[ May 25, 2006: Message edited by: Satou kurinosuke ]
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so there's just no way to be able to know where a certain page came from?

in index.jsp, i clicked the link to target.jsp
and in target.jsp, i did
String prev_url = request.getHeader("index.jsp");

i returned null.
and i also can't use this since what i really want is to get index.jsp
i don't think getHeader is the method i need

isn't getRequestURI supposed to work?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getHeader("Referer");
not request.getHeader("index.jsp");

Read the API for getHeader, and you'll understand that passing "index.jsp" makes no sense. Do you know what a Http Header is ?

getRequestURI() returns the URI for the request, meaning for the target
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm sorry i also don't know what a http header is
but it's working now
thank you so much
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but it's working now

mmmm... don't forget that this is not a good method.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:

mmmm... don't forget that this is not a good method.


True, we have already discuss this issue in other thread.
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why so?
can i have the link to other thread so i can read and know why this is not a good practice?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bernard Sigmund Gustav:
why so?
can i have the link to other thread so i can read and know why this is not a good practice?


Sigmund Gustav, I did search for that thread but was not able find it.
 
Bernard Sigmund Gustav
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh
maybe they already deleted it or something
thanks anyway
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:

mmmm... don't forget that this is not a good method.


Can you elaborate on why you don't think this is a good method
or, if you feel this has been sufficiently covered in another thread, provide a link to that thread?

Saying 'this is not a good method' without saying why and without providing a better alternative isn't very helpful.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Ben,

I've spent enough time in a previous thread to explain this, but don't have the time to get in the discussion again. Sorry, I wish I could find the old thread.

Saying 'this is not a good method' without saying why and without providing a better alternative isn't very helpful.

That's right. I'll be careful.
[ May 25, 2006: Message edited by: Satou kurinosuke ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!