The id Attribute
The id=�name� attribute/value tuple in a jsp:useBean action has special meaning
to a JSP container, at page translation time and at client request processing time. In
particular:
� the name must be unique within the translation unit, and identifies the particular
element in which it appears to the JSP container and page.
Duplicate id�s found in the same translation unit shall result in a fatal translation
error.
The scope Attribute
The scope=�page|request|session|application� attribute/value tuple is associated
with, and modifies the behavior of the id attribute described above (it has
both translation time and client request processing time semantics). In particular
it describes the namespace, the implicit lifecycle of the object reference
associated with the name, and the APIs used to access this association. For all
scopes, it is illegal to change the instance object so associated, such that its
new runtime type is a subset of the type(s) of the object previously so associated.
"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
First.jsp
<%@ page language="java" import="com.mypackage.MyBean" %>
<jsp:useBean id="myBean" class="MyBean" scope="session" />
<jsp:setProperty name="myBean" property="myProperty" value="FirstValue"/>
<jsp:include page="Second.jsp"/>
<jsp:getProperty name="myBean" property="myProperty"/>
Second.jsp
<%@ page language="java" import="com.mypackage.MyBean" %>
<jsp:useBean id="myBean" class="MyBean" scope="application"/>
<jsp:setProperty name="myBean" property="myProperty" value="SecondValue"/>
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
Here, first.jsp talks about session scope and second.jsp talks about application scope and thus two different beans are created (one in each scope).
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
<%@ page language="java" import="com.mypackage.MyBean" %>
<jsp:useBean id="myBean" class="MyBean" scope="session" />
<jsp:setProperty name="myBean" property="myProperty" value="FirstValue"/>
<jsp:include page="Second.jsp"/>
Second.jsp
<%@ page language="java" import="com.mypackage.MyBean" %>
<jsp:useBean id="myBean" class="MyBean" scope="application"/>
<jsp:setProperty name="myBean" property="myProperty" value="SecondValue"/>
First.jsp
<jsp:getProperty name="myBean" property="myProperty"/>