tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Barker" <wbar...@wilshire.com>
Subject Re: HttpSession questions
Date Mon, 02 Jul 2007 01:44:08 GMT

"lightbulb432" <veerukrishnan@hotmail.com> wrote in message 
news:11385434.post@talk.nabble.com...
>
> 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?
>

Charles has already answered this, but another option would be to add the 
ServletContext as a Request attribute in your Servlet/Filter.  I don't know 
your app, so I don't know which is the better design.

> 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?
>

Well, no, the Servlet, Filter, and Session Objects all belong to a single 
ServletContext, so it makes sense that they should be able to access it. 
However, the Request can (and in TC without a sandbox will) be potentially 
reused for requests to many different Contexts.

>
>
>
> Caldarale, Charles R wrote:
>>
>>> From: lightbulb432 [mailto:veerukrishnan@hotmail.com]
>>> 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
>>
>>
>> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
>> 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: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>
> -- 
> View this message in context: 
> http://www.nabble.com/HttpSession-questions-tf4008885.html#a11385434
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message