I am kind of confused about the usage of tags...
Like to set the property of a bean we can use
<jsp:useBean id="useThis" class="com.model.Car" scope="page" > (If a bean does not exist then a bean can be created )
<jsp:setProperty>
</jsp:useBean>
or
<c:set var=useThis scope="page" value="value" /> (bean can also be created like this)
but now sure which one is better and why....
and
To display the bean property we can use
<jsp:useBean>
<jsp:getProperty>
</jsp:useBean>
or
<c: out value="${useThis.name}" default="not set" />
Is there is any kind of rule when to use one thing but not the other... I mean how is the choice made
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
James Tharakan wrote:I am kind of confused about the usage of tags...
Like to set the property of a bean we can use
<jsp:useBean id="useThis" class="com.model.Car" scope="page" > (If a bean does not exist then a bean can be created )
<jsp:setProperty>
</jsp:useBean>
or
<c:set var=useThis scope="page" value="value" /> (bean can also be created like this)
Modern <c:set> is preferred over the venerable and wordier setProperty.
but now sure which one is better and why....
I wouldn't say either one was "better", but since you'll be using the JSTL for other things (iterations, for example) sticking with JSTL tags makes for consistency.
And, no, you cannot create a bean with <c:set>. For that, you'd still use <jsp:useBean> -- when you create beans in a JSP at all, that is.
Is there is any kind of rule when to use one thing but not the other
Here the EL is the preferred mechanism.
getProperty and setProperty are old tags from the days before the JSTL and EL. I'd always use the modern equivalent.