0

Suppose if I have two jsp pages Page1.jsp and Page2.jsp. And if I call Page2.jsp from Page1.jsp.

How to determine in Page2.jsp that this request has come from Page1.jsp?

I tried using following code in Page2.jsp

request.getRequestURL()

But it gives me URL of Page2.jsp.

Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
Bhushan
  • 6,151
  • 13
  • 58
  • 91

2 Answers2

2

You have to use a header with name referer

request.getHeader( "Referer" );

Unlike many other header information, it is not a mandatory header field. Many a times you may not find this header in the request. To overcome that, you need to implement an alternative solution like passing a from request parameter to hold that URI of the page1.

Please refer to an answer on this type of alternate solution here.

Community
  • 1
  • 1
Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82
1
 <% out.println ( "you came from: " + request.getHeader("Referer") ); %>  
  • 1
    It is the same answer given by [Ravinder](http://stackoverflow.com/a/21136885/1031945) 3 mins before. One thing do not use scriptlets in JSP. see [How to avoid Java Code in JSP-Files?](http://stackoverflow.com/q/3177733/1031945) – Aniket Kulkarni Jan 15 '14 at 12:05