File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getHeader("Referer")

 
dale con
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Swapan Mazumdar
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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: .....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's OK

I can use request.getParameter

Thanks
 
Swapan Mazumdar
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic