Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletRequest or HttpServletRequest ?

 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For JSP scopes of request, what class of object is used to store to attributes?
ServletRequest or HttpServletRequest ?
My assumption is HttpServletRequest...am I right ?
 
GuanXing Fung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nazmul
The implicit request object is a sub-type of the ServletRequest class. So, it could be HttpServletRequest. Or it could be some other class, it is protocol dependent.
 
Thambi Rajah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is the ServletRequest class object which is used to store attributes in request scope.
I refer to the following context from SCWCD Kit Book, Section 12.3, pg218.

Data is shared between servlets using the three container objects, ServletContext, HttpSession and ServletRequest.
The JSP technology, since it is based on servlet technology, also uses the three scopes, which are referred to in JSP pages as application, session and request scopes.

Any verification on this matter is welcome.
Thambi
 
Marcelo Sousa Ancelmo
Ranch Hand
Posts: 498
Eclipse IDE Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletRequest is abstract, so we can�t create object of this type.
Also, in the JSP Syntax is declared that the object request is: "Subclass of javax.servlet.ServletRequest".
 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So...whats the conclusion ? ServletRequest ?
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nazmul Huda Sarkar:
So...whats the conclusion ? ServletRequest ?

Yes, it's javax.servlet.ServletRequest as Dave already mentioned. For more information, you can check the JSP 1.2 specs Table JSP.2-1 Implicit Objects Available in JSP Pages.
 
Ajay Hatkar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per JSP 1.1 Specs
3.2.2
The request and response interfaces together describe a protocol-dependent contract between
the JSP container and the class that implements the JSP page. The contract for HTTP is
defined by the javax.servlet.http.HttpServletRequest and
javax.servlet.http.HttpServletResponse interfaces.
So It should be of type HttpServletRequest.
 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yessssss Ashish Kurmi....I'm 100% with u.....If anyone see the converted servlet Java file in work folder, u will find that the signature of service method is :
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException

But, ofcourse HttpServletRequest is a subclass of ServletRequest
[ September 25, 2002: Message edited by: Nazmul Huda Sarkar ]
 
Michael Huang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's HttpServletRequest!
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think that it is HttpServletRequest coz all the HTTP protocol dependent functionality is handeled by it.And as such JSP pages (the request) comes from HTTProtocol ,right?
 
Raj Paul
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attributes are stored in object of class ServletRequest
 
Thomas Hubschman
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is ServletRequest.
HttpServletRequest inherits the method set/getAttribute() from ServletRequest, which is why so many of my fellow coyboys are confused.
from J2EE 1.3 API
javax.servlet.ServletRequest
java.lang.Object getAttribute(java.lang.String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Hope this resolves the issue.
Thomas
[ October 04, 2002: Message edited by: Thomas Hubschman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic