• Post Reply Bookmark Topic Watch Topic
  • New Topic

confused about the usage of JSP tags  RSS feed

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Similarly, i am not sure which one to choose between EL and <jsp:getProperty>
please guide me !!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's pretty much it. Scriptlets are most definitely out. A number of the standard actions have more modern alternatives.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Venerable Bear Bibeault wrote:venerable == old and stately

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


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to be a little less harsh than "antiquated".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!