File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes difference between request and response headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "difference between request and response headers" Watch "difference between request and response headers" New topic
Author

difference between request and response headers

Vasim Patel
Ranch Hand

Joined: Apr 29, 2004
Posts: 87
I am new to Servlets. I am a little confused about headers. This will be a basic question. Also, please let me know if my understanding is correct.

Here the players are: User, Browser, Servlet, Web server

Requests in HTTP are from Browser to webserver. Right?
Responses in HTTP are from webserver to browser.Right?

Servlets residing on the webserver have access to both HTTP requests and responses.

HttpServletRequest wrap the HTTP requests, while HttpServletResponse wraps the HTTP response.

Hopefully things are correct till here.

Now I need to know about headers.
1.What is the difference between Request headers and response headers?

2. Who sets the request headers and how are they used?
If I am right, request headers are set by the user or the browser, so that the servlet knows about the user preference and the browser preference and accordignly respond.

3. Who sets the response headers and how are they used?
This is set by the servlet/webserver, so that the browser can behave accordingly.
Can you give me some typical examples for both request and response?

Thanks and regards
Vasim

And any good short tutorial, which explains the header part.
Response headers are set by the
chandana sapparapu
Ranch Hand

Joined: Sep 28, 2002
Posts: 63
Hi Vasim,
Your understanding is correct. I too had some questions about request & response headers when I was learning Servlets, but there are some examples or tutorials on the net. I am sorry that I dont remember the links. You can easily find them on google.
Pedro Penna
Ranch Hand

Joined: Jun 05, 2004
Posts: 46
The response is generated by the Servlet. You don't need to set response headers manually all of the time, because some headers are generated automatically by default.

I think learning HTTP basiscs can help you learn about requests/responses
W3C HTTP protocol page

If you want pratical examples, I'd suggest building a simple application that listens to port 80 and point your browser at http://localhost:8080/something to see the HTTP headers sent by your browser.

You could also try TELNET or build another simple application that sends messages through port 80 to communicate with other web servers to see the HTTP headers sent to you by the web server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between request and response headers