• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why this request method can be used in this way?!

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone:
I have a question that puzzle me all the time.I want to get the answer exactly.
There is a method in servlet:"PrintWriter out=response.getWriter();"The response be passed into the method using--->void doGet(HttpServletRequest request,HttpServletResponse response){
PrintWriter out=response.getWriter();
...............................
}
My problem is the HttpServletResponse is a interface and the response is a interface also in this method.But the response can invoke its parent interface ServletResponse's method "getWriter()"?!The ServletResponse interface is not been implements and its method is blank!Why the HttpServletResponse interface can invoke the "getWriter()" method?I think it there should be a class that it implements the ServletResponse interface method and so I can use it.But there isn't even I find all the interface in javax.servlet* and javax.servlet.http.*.Can anyone help me answer this question?! Thank you!
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
yes there is a class(or classes) that implements those interfaces, but you'r not suppose to see them. this classes are implemented by the web container provider and you'r using those classes by activating the interfaces.
hope it helps !
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi nitzan levi !
You means it have been instanced by the servlet container?!It equals that the HttpServletResponse is a class in servlet container but not a interface?! :roll:
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What it means is that the class implements the interface. We know nothing about the class except it's declaration looks something like:
public class VendorSpecificHTTPResponse implements javax.servlet.http.HttpServletResponse{

This means that the class is garunteed to implement the getWriter() method.
When the response is created by the server, there would be some code like:

But, since we are not concerned with the details of how the server actaully works, we never see this code and, in fact, cannot even see the VendorSpecificHTTPResponse class.
(If you were interested to know what class you were actually using, you could do:
response.getClass().getName()
and I garuntee you that the result will not be javax.servlet.http.HttpServletResponse)
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joel McNary!
Thank you for answering my question!I understand you means and you are right!That class is hided by servlet container that implements it!Thank you again!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic