Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean name

 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we have same bean name in different scopes like person named bean in request and page scopes?

thanks

Harish
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can have beans stored in different scopes with the same name.
 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got bean name duplicate error when I tried

<jsp:useBean id="person" class="foo.Person" scope="page"></jsp:useBean>
Dog's name is: <jsp:setProperty name="person" property="name" value="harish" />
Dog's name is: <jsp:getProperty name="person" property="name" />

<jsp:useBean id="person" class="foo.Person" scope="request"></jsp:useBean>
Dog's name is: <jsp:setProperty name="person" property="name" value="harish" />
Dog's name is: <jsp:getProperty name="person" property="name" />
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot give the same id to different beans.
Change "person" to something else, it has to be unique.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Satou is correct.

Your original question is regarding having beans in different scopes with the same name. That is possible.

It's not possible to have two beans with the same id on the same page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic