Using JSP code in JavaScript

后端 未结 7 1441
夕颜
夕颜 2020-12-09 05:14

I want to use JSTL\'s fmt tag in JavaScript to localize my alert messages. My JavaScript file is a standalone file and when I include fmt tag in js, the file browser gives J

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 06:08

    You should strive to keep your javascript code in a separate file from the jsp-code. This is to get browser caching, easier maintenance, reuse across pages, and to allow compression.

    I suggest that you create a global object for text in the jsp, to be used by your javascript files. Like this:

    
    

    Later you use it in your javascript:

    alert(text.this_page_name.required_field_error);
    

提交回复
热议问题