• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Want to find out request is sent from which page

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


you came from: http://localhost:8084/WebApplication4/page1.jsp


(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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic