This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Dought about useBean and getProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Dought about useBean and getProperty" Watch "Dought about useBean and getProperty" New topic
Author

Dought about useBean and getProperty

Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

To use the <jsp:getProperty > action, is it required to define the bean using <jsp:useBean> ?

I am asking this question, because I found that the <jsp:getProperty> work on any scoped beans. I tested the following.



Here Person is valid bean.
After running this JSP file the output is narendra.

Any clarification please.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Roy Simon
Ranch Hand

Joined: Aug 26, 2005
Posts: 62
The jsp:getProperty tag is used as follows:
<jsp:getProperty name = "myName" property = "myProperty">
so it is seen that the name attribute has to be an id of some bean. Hence somewhere before the getProperty tag the useBean tag has to be there.
You can check the c:set tag to when is similar to this but only much cooler....
Hope this helps
Regards
Simon
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,


so it is seen that the name attribute has to be an id of some bean. Hence somewhere before the getProperty tag the useBean tag has to be there.


I was also thinking in the same direction. But the above posted code excuted without error. I tested it on tomcat and Sn Java Application Server 8.1. I addition to this, if I try

<jsp:useBean id="pr" class="mypackage.Person">
<jsp:setProperty name="pr" property="name" value="narendra"/>
</jsp:useBean>

<% Person p = new Person();
p.setName("SomeName");
pageContext.setAttribute("pr", p);
%>

The in the same program, I use the following

<jsp:getProperty name="pr" property="name" />

It is printing "SomeName" not "narendra"

Thanks
 
 
subject: Dought about useBean and getProperty
 
Similar Threads
doubts in HFJS
HF page 416 answer for question 3 might be wrong
Whats the error???
jsp:useBean
useBean, getProperty and typecasts