tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smith <d...@cornell.edu>
Subject Re: HttpSession questions
Date Sun, 01 Jul 2007 20:16:54 GMT
It's also available via the servlet class.  See

http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/GenericServlet.html#getServletContext()

If you are trying this via jsp, it should be available via PageContext.  See

http://tomcat.apache.org/tomcat-5.5-doc/jspapi/javax/servlet/jsp/PageContext.html#getServletContext()

--David

lightbulb432 wrote:
> Why is it that you need an HttpSession in order to get a ServletContext? I
> tried to obtain a ServletContext using an HttpServletRequest, but this isn't
> possible in the API, unless you do a
> request.getSession().getServletContext().
>
> This creates a session, however, and I'm not sure I need a session to be
> created at the point in time where I am obtaining the ServletContext - all I
> want to do is have access to something I put in application scope earlier
> on.
>
> If I do a request.getSession(), then a session is started. If I do a
> request.getSession(false), then a NullPointerException will be thrown if I
> call getServletContext() on it. Why has the API been designed in such a way
> - after all, since it's possible to know what servlet context each request
> is going to, then shouldn't you be able to get the servlet context from the
> request?
>
> Thanks.
>   


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