Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletRequest Interface

 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServletRequest is an interface, How does the servlet container implement this interface to create an object out of it ? Which method in this interface returns an object which implements this interface ?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an Interface so that the container knows how to create one, but so that each container is free to create its own concrete implementation of this interface. From point of view of the user, we should only need to know how this class behaves (from the interface) without needing to know how to create one.
If you want to know what the actual class is behind the scenes, try

Dave
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to know what the actual class is behind the scenes, try

code:
--------------------------------------------------------------------------------
String requestClass = request.getClass().getName()
--------------------------------------------------------------------------------
Hi Dave,
How come above code creates an object which implements HttpServletRequest interface ?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't, the container creates an instance and passes it to you. All that you know is that it behaves like the HttpServletRequest interface, you don't need to know exactly what it is. Using the code I gave you, you can see what the implementing class is. It doesn't get created at that stage, it already exists, you're just able to find out what it is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic