aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean query! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean query!" Watch "jsp:useBean query!" New topic
Author

jsp:useBean query!

Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
To share Beans, we use scope attribute in jsp:UseBean. This attribute can take any of the following four values:

Page : Placed in page context and has page level access.
Application : Shared by all servlets/JSPs in same application/servlet engine.
Session : Stored in HTTPSession.
Request : Placed in ServletRequest object.

Can someone explain me the difference between all these scopes by an example. May be say,

2 applications are running in a Tomcat Server.
The pages of first application are App1P1.jsp and App1p2.jsp.
The pages of second application are App2p1.jsp and App2p2.jsp.

===

Is it like this?

Page - available for all transactions within the entire JSP page.

Application - For all servlets of same application (or) Common to all applications, if no explicit application is defined. (how do you define an application explicitly?)

Session - Available to all transactions that happen in the same browser window.

Request - Only for that request.

Can anyone clear my doubt. Thanks in advance.

_Mani


Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
Rodrigo Dinis
Ranch Hand

Joined: May 28, 2003
Posts: 40
Mani,
the scope page is available only to translating page for the client request (one thread to each client) much used on tag libraries. The scope request is similar : an user request generate objects that can be stored on the request time scope. The Application scope is to every servlets/jsps on the same servlet context (one instance of tomcat for example). The session scope exists during the client connection and only to the same client.


Rodrigo Dinis
SCEA
SCJWSD
SCJD
SCBCD
SCWCD
SCJP
CNA
Brasilia - BRASIL
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Page - available for all transactions within the entire JSP page.
Page Scope - attributes are available/accessible only in this JSP.
As soon as the JSP completes the generation of the output,
the attributes are gone!
This has the least scope or the attributes have very short life!

Application - For all servlets of same application (or) Common to all applications, if no explicit application is defined. (how do you define an application explicitly?).
Application Scope - Consider one application only. You cannot share data between different applications with these approaches.(you have to use a different storage mechanism like Database or file means for that).
They are available/accessible to all servlets/jsps of all sesssions(users) of the same application .

Session - Available to all transactions that happen in the same browser window.
Session Scope - Available/accessible to all servlets/jsps of the same application within the same session.(for that client browser on that particular machine which the client is using, in your words: same browser window )
Note: child windows are also part of the same session.

Request - Only for that request.
RequestScope - Yes. Since included JSPs or forwared JSPs use the same request/response objects, attributes stored in the request object in the first JSP can be accessed in the included/forwarded JSPs! Every request from the client-browser is a new request.
[/QB]

In terms of sequence it would be :

1. PAGE
2. REQUEST
3. SESSION
4. APPLICATION

This is based on the life-span of the attributes. Usually attributes stored in the PAGE live for a short time, while attributes stored in the application live for longer time.
[ May 17, 2005: Message edited by: Vishwa Kumba ]
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
(how do you define an application explicitly?)[/QB]


I think in Tomcat, you don't. If you create a new folder containing all your web resources included WEB-INF directory, under web-apps directory, then the folder name is taken as the Web Application Name.

I do not know if there is any other way or it is possible to have alias names for web applications.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean query!