When a JSP page needs to save data for its processing, it must specify a location, called the scope. See e1048 Saving Data in a JSP Page for an explanation of the four available scopes.
Data is saved using a mechanism called scoped variables. A scoped variable has a name, which is of type String and a value, which is of type Object. For non-page scoped variables, it is recommended that the name use the reverse domain name convention (e.g., prefixed with com_mycompany) to minimize unexpected collisions when integrating with third party modules.
When using the JSTL's expression language (see e1065 Enabling the JSTL Expression Language in a JSP Page), the variables in each scope are made available in the implicit objects pageScope, requestScope, sessionScope, and applicationScope.
This example saves and retrieves values in scoped variables in each of the four scopes:
When retrieving a saved value, it is possible to omit the scope. If the scope is omitted, the variable name is automatically searched for in each of the scopes, in the order pageScope, requestScope, sessionScope, and applicationScope.
It is also possible to specify the value to save using the contents of the body, rather than through the value attribute:
value 1 in body
value 2 in body
value 3 in body
value 4 in body
When specifying the value using body contents, the body contents is first trimmed of leading and trailing white space before it is saved. For example,
line 1
line 2
would be saved as:
"line 1\n line 2"