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

HttpServletRequestWrapper?

kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
it is said that when a http request for a servlet is made to a container, the container creates a HttpServletRequest object and passes it to the service method. my questions:

HttpServletRequest is an interface, it can only be a reference to the object of a class that implements it. how then does the container make its object?

the default implementation is present in HttpServletRequestWrapper and ServletRequestWrapper classes. they might be instantiated by the container?
something like this:

HttpServletRequest request;
HttpServletRequestWrapper x = new HttpServletRequest(request);
request = x;
service(request,response);

please clear my doubts.i fail to understand how an object of an interface can be made?
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
The container will either create a new instance of a class that implements HttpServletRequest or recycle one from a pool. In either case you don't have to worry. Code to the interface and you'll be a happy boy. Each server if free to provide an object that implements the interface in any way it sees fit.

The HttpServletRequestWrapper is really meant for developers, not for server providers. Since there are a few places where you must pass the HttpServletRequest (RequestDispatcher, FilterChain), this gives you a way to change the object being passed around if you decide to.
kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
which is the class that implements HttpServletRequest interface? the interface does not have the implementation, do you mean to say that the container provides the default implementations of the methods defined in the interfaces such as getParameter() etc? i guess it is the HttpServletRequestWrapper class.
please guide!

Originally posted by Ken Robinson:
The container will either create a new instance of a class that implements HttpServletRequest or recycle one from a pool. In either case you don't have to worry. Code to the interface and you'll be a happy boy. Each server if free to provide an object that implements the interface in any way it sees fit.

The HttpServletRequestWrapper is really meant for developers, not for server providers. Since there are a few places where you must pass the HttpServletRequest (RequestDispatcher, FilterChain), this gives you a way to change the object being passed around if you decide to.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
1. As Ken said, in order to program servlets, you do not need to know the implementing class. That is why so many of the things you deal with in servlets are Interfaces.

2. If you want to study the actual implementation, it may be different for every servlet container. To find out what your servlet container provides:

System.out.println( request.getClass().getName() ;

should do it. Tomcat comes with the full source so you can look at that.

Bill
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
Most things are interfaces to allow each vendor to provide concrete classes that do things the way they want.

Simply write your code to the classes in J2EE.jar (from sun) and you will be good to go on any J2EE certified server.

Websphere uses a file called J2EE.jar to provide the J2EE functionality while Sybase's EAServer has a file with a name like easj2ee.jar (it's been a little since I've used that, so the name may not be exact). In either case you don't have to care because the server at runtime will reference these classes, and since you've coded to the interface you will be good.

If you code to the Tomcat specific class and then deploy on WebLogic, your code will not run. If you code to the J2EE standard, you should be able to 'plug' your app into any J2EE container.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpServletRequestWrapper?