aspose file tools*
The moose likes Servlets and the fly likes Setting a header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting a header" Watch "Setting a header" New topic
Author

Setting a header

Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
Any idea on how to set a header in the response object? The obvious answer is the setHeader() method, but it doesn't seem to work. I use RequestDispatcher.include() to get to the second servlet, I set the header there, and it returns to the first servlet. When I use the containsHeader(name) method, it returns "true", but when I print out getHeaderNames(), my new header is not there.
Any thoughts?


Gail Mikels
Ken Pelletier
Ranch Hand

Joined: Aug 01, 2002
Posts: 54
As I understand it, a servlet that's included cannot make any changes to status codes or headers; they are ignored.
The spec and the api docs confirm this.
From the javadoc for RequestDispatcher.include():

The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.
Ken Pelletier
Ranch Hand

Joined: Aug 01, 2002
Posts: 54
As I understand it, a servlet that's included cannot make any changes to status codes or headers; they are ignored.
The spec and the api docs confirm this.
From the javadoc for RequestDispatcher.include():

The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting a header