Scope

Scope

Area where instances can be stored. By going through the scope, it is possible to share the instance between the Servlet class and the JSP file.

JavaBeans Classes (instances) based on rules that are stored in scope and easy to reuse

Serialization

Property

getter/setter

Request scope

Available until response is returned HttpServletRequest

Instantiate in request scope

Description


request.setAttribute("Attribute name",instance);

Get an instance from the request scope

Description


Instance type to be acquired Variable name= (Type of instance to get) request.getAttribute("Attribute name");

Session scope

Developer sets expiration date for save instance Can be used across requests

Get session scope

Description


HttpSession session = request.getSession();

Save to session scope

Description


session.setAttribute("Attribute name",instance);

Get an instance from session scope

Description


Instance type to be acquired Variable name= (Type of instance to get) session.getAttribute("Attribute name");

Remove instance from session scope

Description


session.removeAttribute("Attribute name");

Discard session scope

Description


session.invalidate();

Application scope

Available until the end of the application High speed access

Get application scope

Description


ServletContext application = this.getServletContext();

Save to application scope

Description


appliction.setAttribute("Attribute name",instance);

Get an instance from application scope

Description


Instance type to be acquired Variable name= (Type of instance to get) application.getAttribute("Attribute name");

Remove instance from application scope

Description


application.removeAttribute("Attribute name");

Recommended Posts

Scope
About scope
form_with scope
Java variable scope (scope)
Refactoring with scope
Variables / scope (ruby)
Java variable scope
Studying Java-Part 9-Scope
Java session scope
Corresponds to Scope
Master the [Rails] scope!