Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet API  RSS feed

 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,
I need to know, that on what basis it is decided that a method should go in which interface. I was just looking at the Servlet Request & HTTP Servlet Request API. I am not able to understand that why getParameter(String) is defined in ServletRequest & not in HttpServletRequest, technically getParameter is specif to HTTPServlet. similarly why getAttribute(String) is defined in ServletRequest & not in HttpServletRequest. Actually i am trying to logic behind the method definations.

Thanks
Shashank
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any method defined in ServletRequest is -by way of inheritance- available in HttpServletRequest as well. In regards to getParameter and getAttribute, they are not specific to HTTP at all - they applies to all servlets. Of course, currently there are -AFAIK- no non-HTTP implementations of the servlet API, so the question is somewhat moot.
 
Mouly Kumaraswamy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything that is inherent to the HTTP protocol wil be present in the javax.servlet.HTTP package. Albeit it may be confusing at times, a better understanding of HTTP Protocol and Servlet API will give clarity.
For example session is a concept that is specific to HTTP protocol so all session related methods will be in javax.servlet.HTTP package.
Any servlet irrespective of the protocol should be able to send text parameters - that is why getParameter is present in ServletRequest. The same argument applies for getAttribute.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example session is a concept that is specific to HTTP protocol so all session related methods will be in javax.servlet.HTTP package.


Of course, one could have implemented a more generic session framework, and access that through the classes in javax.servlet. HTTP sessions rely on URLs and cookies, but there's nothing HTTP-specific in sessions per se.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!