aspose file tools*
The moose likes Servlets and the fly likes HttpServletRequest Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletRequest Interface" Watch "HttpServletRequest Interface" New topic
Author

HttpServletRequest Interface

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Feb 01, 2003
Posts: 207
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

Joined: Mar 06, 2001
Posts: 13459

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpServletRequest Interface