• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

interface question

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic