File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletRequest / HttpServletResponse.......puzzled!!!

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to servlets and as such facing impediments in my understanding of the subject...at every step. But I am determined to get over it.
Here goes....HttpServletRequest and HttpServletResponse are interfaces and we are required to pass these objects while
calling a servlet. I do not understand how interfaces can be used without they being implemented in the first place.
This is an SOS.
thanks.
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Ranch has a naming policy, described here and "rajendra" is not a valid name. Please choose one which meets the requirements.
Thanks.
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a fairly common question, and not just about Servlets. An interface specifies the methods which a class must have if it implements that interface. An interface mey be implemented by as many classes as you like.
In the particular case of HttpServletRequest and HttpServletResponse these two interfaces are implemented inside the servlet container. When a servlet container invokes the service(), doPost(), doGet() (etc.) methods, it first creates an instance of one of its classes, which happens to implement the HttpServletRequest interface, and then passes that class to your servlet. HttpServletResponse is similar.
For a full example of how this is done, get the source code for any servlet container or servlet-capable webserver, and 'find files' or 'grep' for any java files containing the string 'implements HttpServletRequest'.
 
Rajendra Deshpande
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank Carver,
Thank you for the quick reply.
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And thank you for changing your name so promptly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic