Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpServletRequest and response  RSS feed

 
Malhar Me
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question: HttpServletRequest request , HttpServletResponse response ..... are interfaces.
then how is is possible to use them like.... request.getMethode() or response.sendRedirect()?
How we can use them as a object?
Is their any implementation internally?
PLease help me to solve this confusion....
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malhar More wrote:How we can use them as a object? Is their any implementation internally?

Yes. Implementation provided by the web container.
 
Malhar Me
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1. The servlet container creates an HttpServletRequest and HttpServletResponse objects and passes them as an argument to the servlet's service methods (doGet, doPost, etc).
2. Here Servlet container create objects like : HttpServletRequest request = new HttpServletRequestWrapper();
HttpServletResponse request = new HttpServletResponseWrapper();
3. So thats why we can directly use the request and response as a object.

Please verify.. tell me whether I am right or wrong .
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actual implementation is vendor specific but you don't have to worry about it since they are proper implementation(s) of those interfaces (HttpServletRequest etc..). Actually, those wrapper classes do wrap (decorate) the actual request/response objects (those are provided by the container) so they are used as convenient classes if you want to override only few methods defined in those interfaces. Those wrapper classes by default calls the methods on the object (request/response etc..) they decorate. Did I confuse you ?
 
Malhar Me
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks... for clear the query.
I am looking for that class which implements this interfaces and which container uses. I am just thinking that these are the classes which responsible to create a object.

Its vendor specific, so then now its no confusion.
 
Minh Ngo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

e.g. the Tomcat web container handles the HTTP request from a client and provides you with an instance of the concrete class 'org.apache.catalina.connector.RequestFacade' which extends 'java.lang.Object' and implements 'javax.servlet.http.HttpServletRequest'. The response object is of type 'org.apache.catalina.connector.ResponseFacade' which extends 'java.lang.Object' and implements 'javax.servlet.http.HttpServletResponse'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!