Sharing Session and Application Data
The request scope makes data available to multiple pages processing the same request. But in many cases, data must be shared over multiple requests.
Imagine a travel agency application. It’s important to remember the dates and destination entered to book the flight so that the customer doesn’t have to reenter the information when it’s time to make hotel and rental car reservations. This type of information, available only to requests from the same user, can be shared through the session scope.
Some information is needed by multiple pages independent of who the current user is. JSP supports access to this type of shared information through the application scope. Information saved in the application scope by one page can later be accessed by another page, even if the two pages were requested by different users. Examples of information typically shared through the application scope are information about currently logged-in users and cache objects that avoid unnecessary database queries for data that is the same for all users.
Figure 10-4 shows how the server provides access to the two scopes for different clients.
![]() |
The upcoming examples in this chapter will help you to use the session and application scopes.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
