Spring javascript escape message tag

When we try to display a label from a properties file using spring tags, we can write:

<spring:message javaScriptEscape="true" code="label" />

I can’t find out what is being used javaScriptEscape="true". Why do we need this?

+5
source share
1 answer

If the message is a JavaScript string literal, for example, in

<script>
    function sayI18nedHello() {
        alert('<spring:message javaScriptEscape="true" code="hello" />');
    }
</script>

You will then need this attribute, which avoids single and double quotes, newlines, tabs, etc., to ensure that the generated JavaScript is valid.

+10
source

All Articles