• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to find out request is sent from which page

 
Priya Lavti
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Is there any way in JSP by which we can find which page has sent the request.
For e.g. if A.jsp has sent the request to B.jsp, By any API, can we find out in B that page A has sent the request?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not reliably. Doing so would be a poor practice in any case. Why is this important?

If it's to switch some conditional processing, you should do that with an explicit parameter eather than rely upon some implicit knowledge such as "where did I come from?"
 
Priya Lavti
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is just for debugging.
Coz I am hitting the submit button only once, but the JSP page is called two times and that too happen randomly.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't think of any way to do it without inspecting the method stack or something.

There is great value in asking "can you do it questions." But I am curious as to what is driving you to ask the question in the first place. Might lead to something interesting.

Cheers!
 
pradheesh manohar
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it could be done easily using javascript

embed the below statement inside script tag in your B.jsp ..it will alert with string "http://somecontext/A.jsp" if B.jsp is reached from A.jsp



alert(document.referrer);
[ October 31, 2006: Message edited by: pradheesh manohar ]
 
Natasza Biecek
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Michelle, you can find this value examining request.getHeader("Referer")
if you put this:

in your destination page and invoke this page from another one
you'll see something like that:

(page1.jsp contained a link to page2.jsp in this case)
hmm...it may be used for debugging...why not?
but don't make any decisions inside your code using this value
because you'll build dependency between pages in this way...
so think a moment about Bear Bibeault's post...

regards,
Natasza
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not clear on what you mean by:
if A.jsp has sent the request to B.jsp,


Which of these are you talking about?

1. The HTML page written by A.jsp has a link to B.jsp
2. A.jsp does an include of B.jsp
3. A.jsp does a forward to B.jsp
4. A.jsp does a redirect to B.jsp

Bill
[ October 31, 2006: Message edited by: William Brogden ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Natasza Biecek:
you can find this value examining request.getHeader("Referer")


But, as I said, not reliably. This header is not always set.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic