Forums Register Login

previously discussed question

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Yup. that was one of our favourite discussions.
- m
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 874 times.
Similar Threads
jsp:useBean question
jsp:getProperty calling bean from specific scope
HFSJ 2ed - about <c:set>
Creating a bean in session scope
doubt on getProperty in various scopes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:15:03.