Spring Mvc 3 Populate Javascript Var From Property File
I need to populate a JavaScript variable with a property value (that defined in a property file) when page get loaded . i am using spring mvc 3. is there any best way to do it? app
Solution 1:
- Create an initializer method in the javascript file
- output the properties in the page that includes the js. so that they form a valid javascript structure (array, object, whatever)
- pass the structure to the initializer.
The 1st step may look like (in the .js file):
var options;
functioninit(initOptions) {
options = initOptions;
}
The 2nd step may look like (in your jsp page):
var a = newArray();
<c:forEach items="${properties}"var="entry">
a.push({key: '${entry.key}', value: '${entry.value}'});
</c:forEach>
And finally init(a);
Post a Comment for "Spring Mvc 3 Populate Javascript Var From Property File"