Passing Data from One Page to Another
JSP provides different scopes for sharing data objects between pages, requests, and users. The scope defines how long the object is available and whether it’s available only to one user or to all application users. The following scopes are defined: page, request, session, and application.
Objects placed in the default scope, the
page
scope, are available only within that page.
That’s the scope used in all examples you have seen
so far. The
request
scope is for objects that need to be available
to all pages processing the same request, for instance both the page
that receives the request initially and the page the first page
forwards to. Objects in the
session
scope are available to all requests made from
the same browser, and objects in the
application
scope are shared by all users of the application
(see Figure 10-2). According to the JSP
specification, the name used for an object must be unique within all
scopes. This means that if you have an object named
userInfo in the application scope, for instance,
and save another object with the same name in the request scope, the
container may remove the first object. Few containers (if any)
enforce this rule, but you should ensure you use unique names anyway
to avoid portability problems.
![]() |
The
<jsp:useBean>
action has a scope attribute used to ...
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
