aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes different Scopes In expression language(EL) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "different Scopes In expression language(EL)" Watch "different Scopes In expression language(EL)" New topic
Author

different Scopes In expression language(EL)

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
In scriptless JSPs chapter,(ch-8, Head first sevlet & Jsp) i read about different Scopes, namely pageScope, requestScope, sessionScope, & applicationScope. Can someone explain these terms?


kunal
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
In scriptless JSPs chapter,(ch-8, Head first sevlet & Jsp) i read about different Scopes, namely pageScope, requestScope, sessionScope, & applicationScope. Can someone explain these terms?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Go through this once...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
gopal kishan
Ranch Hand

Joined: Feb 23, 2005
Posts: 99
Kunal,

in EL , there are implicit scope objects, but those objects are not same as JSP implicit objects.

In EL all those implicit objects are map objects except PageContext which is same as JSP pageContext.

requestScope is just a Map of the request scope attributes, not the request object itself

In EL they just help you to specify what scope the values are in , but these are not the original objects, which means in JSP using scriptlet



here request refers to HttpServletRequest where as in EL



I hope you understand this.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks Gopal. But, you didn't understood my question. I want to know , what do you mean by these Scopes.? To be more specific, how can you define them.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

Hi Kunal,

This explanation about scopes in a web-application comes from the Java Blue prints (Designing Enterprise Applications with the J2EE Platform, Second Edition)
4.4.7.1 State Scope
Each item of Web-tier state has scope, which determines the accessibility and lifetime of the item. Web-tier state is accessible to servlets, servlet filters, and JSP pages. Briefly, Web-tier state can be maintained in four scopes:

Application scope is "global memory" for a Web application. Application-scope state is stored in the Web container's ServletContext object. (See the caveat on using context attributes in distributable servlets on page 126.) All servlets in an application share objects in application scope. The servlet developer is responsible for thread safety when accessing objects in application scope. An inventory object in application scope, for example, is accessible to all servlets, servlet filters, and JSP pages in the application. State in application scope exists for the lifetime of the application, unless it is explicitly removed.

Session scope contains data specific to a user session. HTTP is a "stateless" protocol, meaning that it has no way of distinguishing users from one another or for maintaining data on users' behalf. Session attributes are named object references that are associated with a user session. The servlet API allows a developer to create a session attribute and access or update it in subsequent requests. Session-scope state for an HttpServlet is stored in the Web container's HttpSession object (available from the HttpServletRequest argument to the service method). State in session scope is accessible to all Web components in the application and across multiple servlet invocations. However, it is accessible only within an individual user session. An online shopping cart is an example of data in session scope, because the contents of the cart are specific to a single client session and available across multiple server requests. A session ends when it is explicitly closed, when it times out after a period of inactivity, or when its container is shut down or crashes. Unless removed explicitly, state in session scope lasts until the session ends.

Request scope contains data specific to an individual server request, and is discarded when the service method returns. A Web component can read or modify data in request scope and then "forward" the request to another component. The component to which the request is forwarded then has access to the state. State in request scope is stored in a ServletRequest object, so it is accessible to any component receiving the request. Note that the values of query string parameters and form variables are also in request scope. For example, when a servlet places a timestamp in a ServletRequest and then forwards the request to another servlet, the timestamp is in request scope.

Page scope, applicable only to JSP pages, contains data that are only valid in the context of a single page. Page scope state is stored in a JSP page's PageContext object. When one JSP page forwards to or includes another, each page defines its own scope. Page scope state is discarded when the program flow of control exits the page.


Does this answer your question?

Regards,
Frits
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Yes, that's the answer i was looking for..
Thanks Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: different Scopes In expression language(EL)