File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes confused about the usage of JSP tags Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "confused about the usage of JSP tags " Watch "confused about the usage of JSP tags " New topic
Author

confused about the usage of JSP tags

James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

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
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Similarly, i am not sure which one to choose between EL and <jsp:getProperty>
please guide me !!
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Modern <c:set> is preferred over the venerable and wordier setProperty.

how is it venerable ??


And, no, you cannot create a bean with <c:set>.

Actually i forgot to add the bean tag in the post

when you create beans in a JSP at all.

Were you trying to say that we don't really create beans in JSP
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

James Tharakan wrote:
Modern <c:set> is preferred over the venerable and wordier setProperty.

how is it venerable ??

venerable == old and stately

when you create beans in a JSP at all.

Were you trying to say that we don't really create beans in JSP

In a properly structured Model 2 application, most beans will be created in controllers, not in JSPs.

The older tags you are asking about were much more important back in the days before Model 2, JSP 2, and the JSTL and EL.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

So as i understand , in current development the use of scriplets and expressions are not used. And Standard action tags are not preferred much.

Correct me if i am wrong.

Thanks.

Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

That's pretty much it. Scriptlets are most definitely out. A number of the standard actions have more modern alternatives.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
The Venerable Bear Bibeault wrote:venerable == old and stately

Well, one outta two ain't bad...


Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

I wanted to be a little less harsh than "antiquated".
 
 
subject: confused about the usage of JSP tags
 
Threads others viewed
Bean standard action doubt
Head First Servlets and JSP:SCWCD Question
jsp:setProperty without jsp:useBean
"target" version of c:set
Question regarding EL and standard action from HF Servlets and JSP
developer file tools