aspose file tools*
The moose likes JSP and the fly likes Want to find out request is sent from which page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Want to find out request is sent from which page" Watch "Want to find out request is sent from which page" New topic
Author

Want to find out request is sent from which page

Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
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?


-Priya
SCJP 5.0
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

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?"


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Oct 09, 2006
Posts: 10
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

Joined: Oct 26, 2006
Posts: 28
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

Joined: Mar 22, 2000
Posts: 12806
    
    5
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

Joined: Jan 10, 2002
Posts: 61437
    
  67

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.
 
jQuery in Action, 2nd edition
 
subject: Want to find out request is sent from which page