Friday, December 09, 2005

Referer

How to find the request URL? For example if the request is made from
"http://localhost:8080/SecurityCheck/JspOne.jsp " this url, how to get it in the servlet code?

StringBuffer buffer = request.getRequestURL();
String str = new String(buffer);
System.out.println("RequestURL()" + str);


Is there a way to know from which page the request is coming. For example if I have a web application with 10 pages having a link to login page I like to know from which page the request to login page was made?

Referer:
It's an optional header field that contains the URL of the referring document.

The Referer field was designed for link backtracking and verification, not for authentication or session management.

request.getHeader("referer") will give you the source url
<%= request.getHeader("referer") %>


A very good article about referer is here

Take a look at this JavaRanch Thread to know why NOT to rely on referer Header.

0 Comments:

Post a Comment

<< Home