• 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

How can we access the methods in the HttpServletRespone interface

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
How can we access the methods in the HttpServletRespone interface
object without implementing this interface.
ie we are using
public void doGet(HttpServletRequest req, HttpservletRespone res)
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
---------
---------
}

where the setrContentType() and getWriter() method implementations are done. Pls Clarify.
Thank in advance
Suresh K
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suresh,
doGet() is passed a class that implements the HttpServletResponse interface. Each servlet container provides its own implementation. You just call the methods as shown in your example.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suresh,
To give a more elaborate reply, the HttpServletResponse res object that is being passed as a parameter actually is an object of a class that implements the HttpServletResponse interface.
You'll find that most of the time it's the interface that you're using during your Servlet programming. This is because the Servlet specs. doesn't manadate any class names for most of the interfaces. That's left upto the Servlet containers (e.g. tomcat) to design.
So if you try something like, System.out.println(res.getClass()) on your response object, you'll find the class name that the container is actually using.
Since this class implements the interface HttpServletResponse, it is perfectly legal to declare your res object to be of the type HttpServletResponse.
Same is the case with many other interfaces in the Servlet API.
Hope that helps.
 
Suresh Khanna
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thank you Jeanne and Dinesh for your answers.
Dinesh, got the class that is implementing the HttpServletResponse interface
by calling getClass() method. I appreciate your elaborate explanation.

Regards
Suresh K
 
reply
    Bookmark Topic Watch Topic
  • New Topic