Java2all.com  

Scope of JSP objects





Share This Topic -

JSP Scope:

Scope of a JSP object determines whether that is object is available to be used at a particular place in the application or not.Every object created in a JSP page will have a scope.

There are four types of scopes available for JSP objects. These are page, request, session and application.

Page:

‘page’ scope means, the JSP object can be accessed only from within the same page where it was created. The default scope for JSP objects created using <jsp:useBean> tag is page.

JSP implicit objects out, exception, response, pageContext, config and page have ‘page’ scope.

request:

A JSP object created using the ‘request’ scope can be accessed from any pages that serves that request. More than one page can serve a single request.

The JSP object will be bound to the request object. Implicit object request has the ‘request’ scope.

session:

‘session’ scope means, the JSP object is accessible from pages that belong to the same session from where it was created.

The JSP object that is created using the session scope is bound to the session object. Implicit object session has the ‘session’ scope.

application:

A JSP object created using the ‘application’ scope can be accessed from any pages across the application. The JSP object is bound to the application object.

Implicit object application has the ‘application’ scope.

We can easily figure out that the 'page' scope is the least visible and the 'application' scope is the most visible among all the scopes available for JSP objects.