• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between request and response headers

 
Vasim Patel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic