• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bean doubt

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package test;
public class MyBean
{
private String name = "default";
public MyBean(){}
public MyBean(String name){this.name=name;}
public void setName(String name){ this.name = name; }
public String getName(){ return name; }
}



myjsp.jsp
<%
pageContext.setAttribute("bean", new test.MyBean("no name"));
%>

<jsp:useBean id="bean" class="test.MyBean">
<%bean.setName("bean");%>
</jsp:useBean>

Name:<%= bean.getName()%>

when i set "bean" attribute with pageContext my output is "Name:no name"
when i set "bean" attribute with request/application/session my output is
"Name:bean"

what is happening behind the scene can anyone explain in detail?

thanks inadvance
Sravanthi
[ May 30, 2008: Message edited by: Vijaya Sravanthi ]
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Name:<%= account.getName()%>


what is account and where did you declare it?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

when i set "bean" attribute with pageContext my output is "Name:no name"



when you set bean in the pageContext the default scope of jsp:useBean already has the bean(as you haven't given the scope attribute!!) so the body of useBean std action is not executed hence you get the value which you had set while creating the bean.

when i set "bean" attribute with request/application/session my output is "Name:bean"



while when you set it in request/ session/ application scopes useBean tries to find it in page scope (as thats the default) which it doesn't find hence standard actions' body is executed hence creating a new bean in the page scope..confused...!!
the bean already there in the other scope will remain there and a new bean for the page scope will be created by the body of useBean action.

thanks and reagards
Bhupen
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic