I’m trying to localize my application, and it would be nice if I could simply send all JS files through a JSP resolver to get access to localization bundles.
Right now, I just have this:
<bean id="viewResolver" class=
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
and I was wondering if there was an easy way to have both .js and .jsp resolve through the InternalResourceViewResolver without adding in some pattern matching hackery.
You don’t actually need your
.jsfiles to be stored as.js, as long as their content-type istext/javascript. But having dynamic information in your.jsfiles is wrong:Instead, you should initialize some settings object from a jsp page that is using the .js file. See this answer for more details.
Here is a concrete (simplified) example from my code. This snippet is in the
.jsp:The
init(config)is in the.jsfile, and is just setting the config object as a global variable. (I actually have some default values, but that doesn’t matter)