This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi: I am attempting to set an http header and then read it back, like so: //**************************** response.setHeader("someHeader", "someHeaderValue"); response.setContentType("text/html; charset=" + this.getCharacterEncoding()); PrintWriter out = response.getWriter(); out.println(response.containsHeader("someHeader")); out.println("<br />"); out.println("request.getHeader("someHeader")); //**************************** When I compile and run, the response.containsHeader returns true, but request.getHeader always returns null. I originally thought that this was related to the RequestDispatcher I am using in this same servlet, but after stripping the code down to what I wrote above, I still cannot get the header to set correctly. I am using Tomcat 4.1.18; there is one Filter that the request is being passed through, but the header does not set even after I removed the filter (I had read that some versions of Tomcat display buggy behavior with regard to setHEader when filters are used). Anyone have any idea why this is not working? Thanks! Aaron
request and response are separate objects, if you are setting something in response u can't get it it out from request within same piece of code. The reciever will get this response as request and would be able to get this thing out from the request object. -deepak
Joined: Sep 10, 2003
Hi, thanks for the response! I did not correctly state my problem, I guess. The code I gave as an example is not actually in the same file. The request.getHeader("someHeader")' portion is in a separate servlet written simply to check for the existence of the http header I am trying to set. They are not run together. Sorry for the misstatement. However, I still cannot seem to actually set the http header with the response.setHeader() method. The header never shows up. I tried running the same code on another installation of Tomcat and it DOES work there, so I am assuming there is something I am missing that is preventing the code from working correctly on the server it is currently on.