Here is how thing work when you stretch the <jsp:getProperty .... /> in various scopes. The "ID" of the bean is the same "hello" in all the scopes (page|request|session|application) The Bean in my example is same as what ersin used - Has a String field called "beanScope" instead of "name" used by ersin. My conclusion: The (s)getProperty searches for the bean named "hello" first in the page then in request then in the session and finally the application scope. (The page scope is special since using the <jsp:include ...> action will give an error, by design, saying that there is no bean "hello" in the page scope.) You can test this by changing the scopes of the beans created in the files "two.jsp" and "three.jsp" (or one.jsp for theat matter). one.jsp <HTML> <head><Title>ersin</title></head> <body> <jsp:useBean id="hello" class="madhav.bean1.TestBean1" scope="application" /> <jsp:setProperty name="hello" property="beanScope" value="Ersin" /> Hello, <jsp:getProperty name="hello" property="beanScope"/>!<P> <jsp:include page="two.jsp" /><BR> <jsp:setProperty name="hello" property="beanScope" value="Satya" /> Hello, <jsp:getProperty name="hello" property="beanScope"/>!<P> <jsp:include page="three.jsp" /><BR> <jsp:setProperty name="hello" property="beanScope" value="Guy" /> Hello, <jsp:getProperty name="hello" property="beanScope"/>!<BR> <P> This is Request <%=((madhav.bean1.TestBean1)request.getAttribute("hello")).getBeanScope() %><BR> This is Session <%=((madhav.bean1.TestBean1)session.getAttribute("hello")).getBeanScope() %><BR> This is Application <%=((madhav.bean1.TestBean1)application.getAttribute("hello")).getBeanScope() %><BR> </body></html>
two.jsp ========= <jsp:useBean id="hello" class="madhav.bean1.TestBean1" scope="request" /> I come from two.jsp<BR> three.jsp ========== <jsp:useBean id="hello" class="madhav.bean1.TestBean1" scope="session" /> I come from three.jsp<BR>
The output from Tomcat with this combination is: Hello, Ersin! I come from Two.jsp Hello, Satya! I come from three.jsp Hello, Guy! /******************************/ This is Request Guy This is Session notSet This is Application Ersin /******************************/
can some body explain why the above output is generated.......pleaseeeeeeee
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Yup. that was one of our favourite discussions. - m