IaCoder
IaCoder

Reputation: 12770

Is it really a best practice to use jstl out tag?

I remember working on a project with a group of developers and they always wanted static html text to be inside of an out tag (<c:out value="words" />). I don't remember why this was the case.

Is this really a best practice when building jsp pages? What are the advantages/disadvantages of such an approach?

Upvotes: 4

Views: 2569

Answers (2)

Bill the Lizard
Bill the Lizard

Reputation: 405795

If you're just printing out plain text it's better to do it in HTML. The advantage of the c:out tag is that you can evaluate expressions inside the tag.

<c:out value="Hello ${user.firstName} ${user.lastName}"/>

Upvotes: 3

MetroidFan2002
MetroidFan2002

Reputation: 29898

It is a terrible idea for static text. You then have no barrier as to what is static and what is dynamically generated.

Besides which, on Servlet Spec 2.3+ you can have dynamic text mixed with static text as:

This is static, not ${dynamic} text.

The only reasons to use c:out tags, in my experience:

  1. You're using an older servlet spec, and need them to output DYNAMIC text in some fashion

  2. You want to escape HTML output to avoid using <>, etc, replacing ampersands with their control codes, etc.

Otherwise, having them use static text confuses the programmer or maintainer...now where did I put that EL? It was in a c:out tag...but so was fifty other lines of static text!

Upvotes: 11

Related Questions