This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean related doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean related doubt" Watch "jsp:useBean related doubt" New topic
Author

jsp:useBean related doubt

Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
In HFSJ(pg 416),they have this in one of the "BE he Container" sections:


They say this would fail:

Reason for failure:


But,I was wondering,so what would work,would this be the right solution.Would this work:


thanks in advance.
[ June 27, 2006: Message edited by: Jas Oberai ]

SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
Jan Kostelansky
Greenhorn

Joined: Nov 24, 2005
Posts: 11
The reason, why it does not work, is jsp:useBean standard action's default scope is page.
It is impossible to set attribute into page scope in servlet.
If appropriate scope attribute is added into jsp:useBean, the example should work.


Jan
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
cool....thanks Jan
[ June 27, 2006: Message edited by: Jas Oberai ]
sarang bharambe
Ranch Hand

Joined: Apr 01, 2005
Posts: 40
Hey friends,
I am confused about all this discussion.


Actually the handwritten note on the page 416 in HFSJ says,
the tag body executes ONLY if a new bean is created....

But when is the new bean is created??
Is it when,<jsp:useBean> tag is encountered or anytime else?

Can anyone throw light on this?

Thanks in advance

Sarang bharambe


SCJP 1.4 (86%)<br />SCWCD 1.4 (86%)<br />----------<br />If You dont succeed at first time,call it Version 1.0 !!!
Raghusham Sankargal
Ranch Hand

Joined: Oct 10, 2005
Posts: 59
Hi,

According to the question I do not think the tag will work.even if you changed the scope to request in the tag. This is because the new attribute is not created if you are not using class attribute. As we have only type then and when ever only type attribute is used then we should ensure that the bean is already present.


Raghusham Sankargal
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
If you specify type without a class then the bean name must exist in the specified scope,if no scope is specified the default is page.

<jsp:useBean id='person' type='foo.Employee'>
<jsp:setProperty name='person' property='name' value='Fred'/>
</jsp:useBean>

In this case type is used...so the bean person must exist in the page scope...otherwise you wil get an exception.


Corect me if i am wrong


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
The exception will not arise If you add scope="request" .(hope the bean 'person' is in the request scope).
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
You just need to add the request scope and it works fine i.e.:

<jsp:useBean id='person' type='foo.Employee' scope="request">
<jsp:setProperty name='person' property='name' value='Fred'/>
</jsp:useBean>


Because in the servlet,you are setting the bean in the request scope.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean related doubt
 
Similar Threads
doubt in jsp:usebean
Is this an error in HFSJ ??
jsp:useBean
HFSJ: Be the Container: page 358
jsp:useBean doubt?