• Post Reply Bookmark Topic Watch Topic
  • New Topic

interface question

 
Tony Smith
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I been told HttpServletrequest and HttpServletresponse are interfaces. I also been told interface can't create objects only reference variables. So,

HttpServletrequest request and HttpServletresponse response, are request and response objects or reference varaiables? If they are objects can you explain to me what is going on? If they are reference varaiables, what do they refernce to? what classes were initialized for them to refence to?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the API provides the interface. The container makers provide the implementation.

In other words, someone has to make a concrete class to be used.

If you're interested in seeing what the class name of the implementation that you're using is, paste the following code into a JSP and hit it with your browser:


When I do this with Apache Tomcat I can see that the object being passed to my JSP is an instance of: org.apache.catalina.connector.RequestFacade which, of course, implements javax.servlet.http.HttpServletRequest.
[ July 15, 2007: Message edited by: Ben Souther ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are proper objects, but only part of them is exposed to the developer - namely the interfaces they implement. You can get the name of the class by doing something like "request.getClass().getName()".

The important point is that all the developer needs to know is that he's getting handed an object that (at the very least) implements the request interface. That object will have other methods, but those are hidden from view because they are exposed through those interfaces. What the actual package and class name is is up to the servlet container (and will differ from container to container).

The JDBC API (amongst others) works like this as well - the developer uses the Connection, Statement and ResultSet interfaces, and it's up to the driver to create objects that implement those interfaces.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
They are proper objects, but only part of them is exposed to the developer - namely the interfaces they implement. You can get the name of the class by doing something like "request.getClass().getName()".

The important point is that all the developer needs to know is that he's getting handed an object that (at the very least) implements the request interface. That object will have other methods, but those are hidden from view because they are exposed through those interfaces. What the actual package and class name is is up to the servlet container (and will differ from container to container).

The JDBC API (amongst others) works like this as well - the developer uses the Connection, Statement and ResultSet interfaces, and it's up to the driver to create objects that implement those interfaces.


Beat ya!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!