JSP : JSTL's tag

后端 未结 5 863
迷失自我
迷失自我 2020-11-29 16:22

Writing a JSP page, what exactly does the do? I\'ve noticed that the following both has the same result:

The person\'s na

相关标签:
5条回答
  • 2020-11-29 16:32

    c:out also has an attribute for assigning a default value if the value of person.name happens to be null.

    Source: out (TLDDoc Generated Documentation)

    0 讨论(0)
  • 2020-11-29 16:33

    As said Will Wagner, in old version of jsp you should always use c:out to output dynamic text.

    Moreover, using this syntax:

    <c:out value="${person.name}">No name</c:out>
    

    you can display the text "No name" when name is null.

    0 讨论(0)
  • 2020-11-29 16:35

    c:out escapes HTML characters so that you can avoid cross-site scripting.

    if person.name = <script>alert("Yo")</script>

    the script will be executed in the second case, but not when using c:out

    0 讨论(0)
  • 2020-11-29 16:35

    Older versions of JSP did not support the second syntax.

    0 讨论(0)
  • 2020-11-29 16:38

    You can explicitly enable escaping of Xml entities by using an attribute escapeXml value equals to true. FYI, it's by default "true".

    0 讨论(0)
提交回复
热议问题