Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

previously discussed question

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup. that was one of our favourite discussions.
- m
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic