File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can an attribute be duplicated in different scopes

 
Sue Pillai
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For quick tests, yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic