Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP/JSTL using or not using <c:out> tags

Tags:

java

jsp

jstl

i'm helping develop a java jsp jstl based web service and all dynamic objects are being inserted using ${object.foo} and i was wondering if it made a difference whether or not it was actually in <c:out value="${object.foo} />?

the pages all load correctly, but i wonder if there is something that i'm not seeing that may be an issue.

like image 259
harryBundles Avatar asked Aug 06 '10 12:08

harryBundles


3 Answers

when you use JSTL core out tag, you have some more options:

  • The values that you are passing to the tag will be by default XML-escaped
  • You can provide a default value which will be displayed if the value passed is null.
like image 158
Marimuthu Madasamy Avatar answered Nov 01 '22 15:11

Marimuthu Madasamy


Use EL expressions, and if you need output escaping then use the fn:escapeXml function like ${fn:escapeXml(myText)}.

like image 21
Behrang Avatar answered Nov 01 '22 16:11

Behrang


In previous versions of jsp it was not possible to directly use el expressions in text content, you had to use c:out. This is no longer neccessary, using el expressions directly for output creates a much less cluttered jsp in my opinion. The c:out tag still has its uses if you need to control output escaping via the escapeXml attribute.

like image 1
Jörn Horstmann Avatar answered Nov 01 '22 14:11

Jörn Horstmann