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

馋奶兔 提交于 2019-12-18 06:07:24

问题


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.


回答1:


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.



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/3423598/jsp-jstl-using-or-not-using-cout-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!