• 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

How can an attribute be duplicated in different scopes

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With reference to HF's Servlets & JSP: (pg 385)

One of the reasons you use the scope implicit objects is to avoid a potential naming conflict. How can I have the same id for two useBean tags? When I try to set an attribute with the same name in request scope and session scope using:

<jsp:useBean id="person1" class="com.example.Person" scope="request">
Setting Request Attribute:
<jsp:setProperty name="person1" property="userName" />
</jsp:useBean>
Getting Request Attribute:
<jsp:getProperty name="person1" property="userName" />
<br>

<jsp:useBean id="person1" class="com.example.Person" scope="session">
Setting Session Attribute:
<jsp:setProperty name="person1" property="userName" />
</jsp:useBean>
Getting Session attribute:
<jsp:getProperty name="person1" property="userName" />

I am getting the foll error:

org.apache.jasper.JasperException:jsp.error.useBean.duplicate /CheckAction.jsp

I am trying to create a situation where there is a same-named attribute in 2 different scopes (say request and session) and figure out what it prints with and without using implicit objects. How do I go about it?

(I know I am being a hard-nut, but I just scored 50% in that chapter's mock and thought I'll be better off trying every silly thing out on the system )

Thanks.
[ February 06, 2006: Message edited by: Sue Pillai ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't like that the id attribute is the same in both tags.

A quick and dirty way to do your test is to use a quick scriptlet at the top of the page to set the values:

<%
request.setAttribute("sameName", "Request Value");
session.setAttribute("sameName", "Session Value");
%>
 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marc, It worked that way. I guess that is why scriptlets are useful sometimes, huhn!
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For quick tests, yes.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic