This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi all I have a question about scope in JSP When I type <jsp:useBean id="hello" class="ABC"/> I know that the default scope is "page". Therefore, it is no doubt that I can use all the implicit objects in this scope. However, (1)I can still use the implicit object "application" without specify the scope ="application" (2) I can't use the implicit object "session" without specify scope="session" I got th following observation: 1) scope="page" , all page implicit object + "application" 2) scope="session", ? 3) scope="application", ? 4) scope="request" ? Please correct me if I make any mistake I am using Tomcat 4.0 Many thanks Edwin [ April 03, 2002: Message edited by: Edwin Wong ]
The scope of a bean is different from implicit objects. There is no relation between declaring the scope of an object and the use of implicit objects (well, ofcourse other than they share they same name unfortunately). When you specify a scope for a bean, the bean is now associated to that "scope". But this has nothing to do with wether you can access the implicit objects in a JSP or otherwise. regds. - satya
Hi, What does a scope mean then Not a specific range of data's accessibility? For example, a variable defined in request scope has not any intervention from request to request, but a variable in session scope does.
Therefore, it is no doubt that I can use all the implicit objects in this scope.
Implicit objects have clearly defined scopes (see JSP.2.8.3 Implicit Objects of the JSP 1.2 specs), although they can be made unavailable by a page directive.
There is no relation between declaring the scope of an object and the use of implicit objects (well, ofcourse other than they share they same name unfortunately).
What satya was trying to say is that, for example, the identifier session inside a JSP may either mean: (a) a value for the scope attribute in a <jsp:useBean> tag, or (b) the session implicit object which are two different things, although, of course, the implicit object session is of session scope (that should have naturally implicit ). -anthony
Edwin Wong
Greenhorn
Joined: Apr 15, 2001
Posts: 10
posted
0
Dear all Thanks for all your reply ! After I have read the specification of JSP carefully, I got a new picture. I understand the scope of useBean tag is not related to the implicit objects. sorry As Madhav said, unfortunately they use the same name. I found the step for instant a JSP tag in the following url : http://java.sun.com/products/jsp/tags/10/syntaxref10.fm14.html According to the above url: ---------------------------------- The <jsp:useBean> tag attempts to locates a Bean, or if the Bean does not exist, instantiates it from a class or serialized template. To locate or instantiate the Bean, <jsp:useBean> takes the following steps, in this order: 1)Attempts to locate a Bean with the scope and name you specify. 2)Defines an object reference variable with the name you specify. 3)If it finds the Bean, stores a reference to it in the variable. If you specified type, gives the Bean that type. 4)If it does not find the Bean, instantiates it from the class you specify, storing a reference to it in the new variable. If the class name represents a serialized template, the Bean is instantiated by java.beans.Beans.instantiate. 5)If it has instantiated (rather than located) the Bean, and if it has body tags (between <jsp:useBean> and </jsp:useBean> , executes the body tags. ---------------------------------- The scope in useBean tag is used for locate bean only Cheers Edwin [ April 04, 2002: Message edited by: Edwin Wong ] [ April 04, 2002: Message edited by: Edwin Wong ]