This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting headers  RSS feed

 
Charith Fernando
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

response.setHeader("tes", "49");
RequestDispatcher dis = request.getRequestDispatcher("test1.jsp");
dis.forward(request, response);

i have the above code written in a file called test.jsp and the below code is from the test1.jsp

Header infor :<%= request.getHeader("tes") %><br>

but this returns null why is that?
 
Marcelo Ortega
Ranch Hand
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look carefully at your code.
You are setting a header to the RESPONSE object, not the request (because you can't), and since you the response object hasn't got a getHeader() method, you are trying to get it from the ORIGINAL request (where it obviously does not exist). Thus you null result.

Regards,
Mars.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!