All components access available WebFigures by using web server cache mechanisms. This allows you to leverage built-in J2EE mechanisms to scale your servers into a farm and automatically propagate the session across the servers.
There are a number of ways to attach a WebFigure to a scope, depending on the state:
Attaching to the session cache session
Attaching to the application cache application
The session cache is visible only to the current user in a system and is usually used to store user session-specific information. When the user disconnects from the web server, the session cache is cleared.
Attaching to the session cache can be an ideal choice if the figure is valid only for a specific user, at a certain time.
To do this, add the following line of code to a JSP scriptlet or a servlet:
//from a JSP scriplet or a servlet to the Session cache request.getSession().setAttribute("myFigure", myFigure);
Use the tag attributes to associate the WebFigure tag with the attached WebFigure instance:
name="myFigure" scope="session"
Note: The name given to the JSP tag must match the one used to attach it to a cache, and the name must be unique within that cache. |
The application cache is visible by all sessions in the current application. It persists until the web application shuts down.
Attach to the application cache if you want to attach the figure globally for every page and servlet to use.
To attach to the application cache, add the following line of code to a JSP scriptlet or a servlet:
//from a JSP scriplet or a servlet to the Application cache request.getSession().getServletContext().setAttribute("GlobalFigure", myFigure);
Use the tag attributes to associate the WebFigure tag with the attached WebFigure instance:
name="GlobalFigure" scope="application"
Note: The name given to the JSP tag must match the one used to attach it to a cache, and the name must be unique within that cache. |