tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lightbulb432 <>
Subject RE: HttpSession questions
Date Sun, 01 Jul 2007 20:37:48 GMT

I did notice the getServletContext() of the servlet classes, but in this case
the code is in a custom class that was forwarded to by the servlet - I don't
have access to the servlet in this class.

If however, I were to change my code and pass the return value of Servlet's
getServletContext() to my class, would a session still be created, as
happens using the request.getSession().getServletContext() approach?

Out of curiosity, why is there a getServletContext() on HttpSession? Pardon
my ignorance, but that just doesn't seem "right" - if it's there as
convenience, then shouldn't it be on the HttpServletRequest class as well?
If that's just the way it is, then that's fine... But is there some design
reason you can think of that the method is in the session but not request
object? Am I missing something here?

Caldarale, Charles R wrote:
>> From: lightbulb432 [] 
>> Subject: HttpSession questions
>> Why is it that you need an HttpSession in order to get a 
>> ServletContext?
> You don't - since your code is in a class that extends HttpServlet, just
> call getServletContext() directly; it's defined under
> javax.servlet.GenericServlet.
>  - Chuck
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
> ---------------------------------------------------------------------
> To start a new topic, e-mail:
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View this message in context:
Sent from the Tomcat - User mailing list archive at

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message