Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting headers

 
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!