• 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

request.getHeader("Referer")

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I have 2 jsp pages, first.jsp redirects to second.jsp

first.jsp
<%
response.sendRedirect("http://localhost:8080/seccond.jsp");
%>


On second.jsp i'm using request.getHeader("Referer") to get the url of where i've just come from, but request.getHeader("Referer") is null

second.jsp
<%
out.println(request.getHeader("Referer"));
%>


can anyone tell me what i'm doing wrong?

Thanks for any help
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dale con:
...
On second.jsp i'm using request.getHeader("Referer") ...


Hi Dale,

You might try the following codes to check the headers name/value. You might should use request.getHeader("referer") instead.

Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = request.getHeader(name);
out.println(name + " = " + value);
}

-Swapan
 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks for your code. I've tried request.getHeader("referer") but i still get a null value ad i also tried


Enumeration e = request.getHeaderNames();

while (e.hasMoreElements())
{
String name = (String)e.nextElement();
String value = request.getHeader(name);
out.println(name + " = " + value);
}


But i don't get the Referer: .....
 
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
As you have seen the referrer header cannot be counted upon. What were you planning to use it for?
 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's OK

I can use request.getParameter

Thanks
 
Swapan Mazumdar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dale con:
It's OK

I can use request.getParameter

Thanks


Hi Dale,

Can you explain how did you help yourself. Theoretically headers and form-data are so much different. What did you want to perform and how did you achieve it. I am just being curious.

-swapan
 
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
My assumption was that originally the OP was using the value of the referrer to switch behavior on the target page. This is not a good way to do this even if the referrer value was reliable since it creates artificial binding between the pages. Now, I assume that the OP is passing an explicit parameter to cause the page to change its behavior which is a much better approach.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic