> [...]
> Greetings,
>
> I was wondering what is the difference between these two ways of
> handling attributes:
>
> 1)[req is the HttpServletRequest parameter of the service() method in
> HttpServlet]
> ...
> HttpSession session=req.getSession(true);
> MyObject myObject=(MyObject)session.getAttribute("xxx");
> ...
> or
> 2) [using the getContext() of HttpServlet object]
> ...
> MyObject myObject=(MyObject)getContext().getAttribute("xxx");
> ...
>
> If they do the same thing, what is the preferable / recommendable way?
>
> thanks,
>
> Pedro Salazar
> [...]
Hi :-) there are at least 3 kinds of getAttribute/setAttribute/removeAttribute
in ServletAPI:
- javax.servlet.ServletContext.getAttribute/setAttribute/removeAttribute
- javax.servlet.http.HttpSession.getAttribute/setAttribute/removeAttribute
- javax.servlet.ServletRequest.getAttribute/setAttribute/removeAttribute
for example:
- javax.servlet.ServletContext.getAttribute/setAttribute/removeAttribute
it can be used to bound a object which is "context-wide", for example, a
DBConnectionPool which is used by all the MyServlet(s) in this context
- javax.servlet.http.HttpSession.getAttribute/setAttribute/removeAttribute
it can be used to bound a object which is "session-related", for example, a
shopping-car EJB object of the client "who is in another side of this
session" :-)
- javax.servlet.ServletRequest.getAttribute/setAttribute/removeAttribute
it can be used to bound a object, and forward that object to anther
MyServlet with "RequestDispatcher"
Bo
June 25, 2001
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html