File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Adding and removing headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Adding and removing headers" Watch "Adding and removing headers" New topic

Adding and removing headers

mohamed zafer
Ranch Hand

Joined: Nov 03, 2000
Posts: 62
Hello there,
The request to my servlet, can have no HTTP headers. In this case I should add HTTP headers before sending it to the servlet. Also the response coming from the servlet should be stripped down of the HTTP header's before leaving the server. Heard that filters can be used for this purpose.
Someone please shed more light on how to do it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

It's probably not a good idea to be dependent on the absence of HTTP headers either coming or going. They're there for a reason.
If your client is a Java client, you can do the next best thing - contact the server with an HttpURLRequest and simply ignore the headers - which you won't even see.
On the other hand, if you truly need a protocol that is like HTTP but without headers, you should write your servlet using the non-HTTP Servlet base class (which itself serves as the base class for HttpServlet). You'll also have to configure your container to use a non-HTTP conduit, and the details of this you'll need to get from the docs specific to your appserver.
Just as a reminder, you can't use this technique to attempt to wrench the servlet architecture into behaving like a client/server system. As long as it's a servlet, it's still contrained to strict request-response communications whether it uses HTTP or not.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Adding and removing headers
It's not a secret anymore!