Search code examples
javaspringjspspring-mvcspring-tld

spring.tld tag library attributes differences


In many tags of spring.tld there are those attributes: htmlEscape javaScriptEscape

The question may seem trivial, but which is the difference from html escape and javascript escape in this context?


Solution

  • Well the htmlEscape is use to escape literal within the html document. like for example, if the html document contains special characters, it will be escaped as follows:

    Original : <    >    "      &
    Escaped  : &lt; &gt; &quot; &amp;
    

    Javascript escape will apply across javascript literal. Suppose I have the literal:

    <script>
        function helloWorld(){
            alert('<html:message javaScriptEscape="true" code="hello" />')
        }
    <script>
    

    Applying a javascript will escape the single and double quotes, the newline chars, the tabs, etc.