• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Session Attributes and ServletContext

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Iam reading the Head First Servlets and JSP by K&B&B.
In the Mock Test of the Session Management chapter, I see the following statement(Q-7) being stated as TRUE:

Attributes bound into a session are available to any other servlet that belongs to the same ServletContext.

I am trying to know:
How are the Session Attributes related to the Servlet Context?
so that they can be accessed by any Servlet.

Iam Confused.

Can somebody help me understand the concept in the above statement.
Thanks,
Ravi.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How are the Session Attributes related to the Servlet Context?
so that they can be accessed by any Servlet.



Here the servlet context means the current web application. Don't try to realate session object with servletContext object.

What they mean is if two servlets are in the same web application (servletContext) session object is sharable among these servlets

Regards
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A ServletContext represents one web application.

A context is the root of the web application. In a url like http://domain ort/ctx, ctx is the context root of the application. The web application will usually be deployed as a war with the same name 'ctx' or in exploded directory format where the top level directory name is 'ctx'.

A j2ee web container may host several such web-applications. Each web application may have several servlets, jsps and several other static resources associated with it. All resources live under the root folder that's the context in a manner dictated by the j2ee spec. The container on initialization assigns a context to each web application that's deployed within it (as a war file or in exploded directory format).

A Session exists per Context. Once a session is created for a Context, this session can be accessed and modified by all other resources (Servlets, Jsps) that belong to this Context. A Servlet would belong to that context by virtue of
1. being registered in that web application's web.xml and/or
2. Its class files located under the root folder of that context. (in the WEB-INF/classes directory under the root folder that represents one context)
The same hold true for jsps too though the location that they are stored and the way they are registered (optional) differ from Servlets.

Thanks,
Ram.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Attributes bound into a session are available to any other servlet that belongs to the same ServletContext.



It should also say "and can be retrieved from any request that belongs to the same session".
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic