File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting a header

 
Gail Mikels
Ranch Hand
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ken Pelletier
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic