Win a copy of Java 9 Revealed this week in the Features new in 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!