Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

html

jsp

jstl

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?

like image 731
IaCoder Avatar asked Dec 10 '22 22:12

IaCoder


1 Answers

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!

like image 163
MetroidFan2002 Avatar answered Dec 22 '22 01:12

MetroidFan2002