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
is it possible to treat .js file as .jsp file using web.xml configuration?
Yes:
scriptjsp
/script.jsp
scriptjsp
/script.js
But, there is no actual advantage in doing this, because JavaScript files do not have to have URLs ending in ‘.js’. What determines whether a file is a JavaScript file is what MIME media type it is served as. You can set this from JSP using:
<%@ page contentType="text/javascript" %>
at the top. Then you can link directly to:
(Aside: in current browsers, scripts linked to with the
(changing 'en' to match whichever language you want), and in that file define a lookup like:
var msg= {
messageName: 'Message in English',
...
};
Then look up msg.messageName for each localisable string in the script.