Struts and Scope
Struts stores objects that can be shared and configured using:
- public void setAttribute(String name, Object obj)
- public Object getAttribute(String name)
These objects have lifetime and visibility according to the following scopes:
- Request Scope (javax.servlet.http.HttpServletRequest):
Can set attributes for the lifetime of a request
- Useful when delegating a request from one servlet to another
- Session Scope (javax.servlet.http.HttpSession): Web
container creates an object that can identify a user across multiple
page requests
- For example, can store Locale information
- Developer must provide synchronization if necessary
- Struts uses session scope extensively
- Application Scope (javax.servlet.ServletContext):
objects visible to all clients and threads of the current web app
- Struts uses application scope to store JavaBeans visible to all
users
- Page Scope (javax.servlet.jsp.PageContext): accessible
only within the JSP page in which created