Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

converting servlet response object to http response object

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How the conversion happens? I know the servlet's response object is a java object, but what about the other, the HTTP response object?

Thanks in Advanced!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServletResponse is-a ServletResponse
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:HttpServletResponse is-a ServletResponse


Then, HttpServletResponse is also a java object, but, the HTTP is a protocol, how do they mapped from a method's parameter to a HttpServletResponse object? I'm a newbie!

Thanks in Advanced!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container reads the data from the HTTP stream and creates the object using the information.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then think of a Servlet as a Java Application that runs inside a servlet container (like Tomcat) and gets executed once a request comes in.
The HTTP request is a series of bits in a stream, typically but not necessarily text data.
The container accepts the request, reads it and then parses the information into an internal representation.
The internal concrete implementation must implement the HttpServletRequest interface, but as long as it 'behaves like' a HttpServletRequest you don't care what the actual class is.
The container then passes this instance to the Servlet so that the servlet can manage the request.

The Servlet container knows you will want to send a response, so it again creates a class that behaves like a HttpServletResponse and gives that to the servlet to return the response.
Once the Servlet is done, the container once again takes responsibility for taking the data from the HttpServletResponse and sending it to the HTTP client.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, what Bear said. I think mine was worth the extra 39 seconds though
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, this is a great help! Thanks David O'Meara and Bear Bibeault!
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!