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
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply 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: 56554
    
  14

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 4967

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!


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
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: 12327
    
    1
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 ]

Java Resources at www.wbrogden.com
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56554
    
  14

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Want to find out request is sent from which page
 
Similar Threads
error page problem
HTTP request header sent by I.E.
Forwarding Pages in JSP
Redirecting servlet response between windows
Request Handling