Consider the following code written by me while studying the use of
java beans with <
jsp:include>. I have a java beab name AddressBean1 which has a property "street".
MyBean.jsp is:
second.jsp is :
when i access the MyBean.jsp i get the response:
second page
secondvalue
this is because both pages share the request scope attributes , so the first javabean object created is referenced in teh second page and its property street is overridden to the secondvalue.
Now if i change the scope in the second page to "page" that is in the second.jsp, i write:
<jsp:useBean id="myBean" class="info.AddressBean1" scope="page" />
and the whole code remains the same, then i get :
second page
firstvalue
this is because in second.jsp the bean is created in its page scope which is not shared, so when the control returns to MyBean.jsp page , it accesses its bean which is in requestscope, so it gives firstvalue.
now if i change the same line in second.jsp to either
<jsp:useBean id="myBean" class="info.AddressBean1" scope="application" />
or
<jsp:useBean id="myBean" class="info.AddressBean1" scope="session" />
i get the result:
second page
secondvalue
which i do not understand why. According to my understanding, the bean created in either session or application is not shared between the two pages ( only the request scope attributes are shared in case of dynamic inclusion <jsp:include>) so when the control goes back to MyBean.jsp, it should access the bean in its request scope and its value of street property "firstvalue".
Can anyone explain this behavior of jsp:useBean and jsp:include and correct me where i am making a mistake??