1

I have some javascript files that need to be dynamically generated. It's purely i18n stuff, and I use the struts 2 convention plugin. I'm successfully able to do this when I omit the .js extension from both the URL and the source file, like this:

Convention Plugin will hit this JSP:

WEB-INF/content/dynamic-javascript-file.jsp

with the URL in this page:

<html>
<head>
<script type="text/javascript" src="dynamic-javascript-file"></script>
</head>
<body>
    blah blah blah
</body>
</html>

BUT, what I would like to do is this:

WEB-INF/content/dynamic-javascript-file.js

And

<html>
<head>
<script type="text/javascript" src="dynamic-javascript-file.js"></script>
</head>
<body>
    blah blah blah
</body>
</html>

Note, the only difference is that both the url and the file itself have their native .js extension. The motivations for this are to keep from confusing devs and tools. Also note, another requirement is that other javascript files should be served as static resources.

chad
  • 7,369
  • 6
  • 37
  • 56
  • What if you .jsp file is named `dynamic-javascript-file.js.jsp`? – Julien Royer Nov 08 '12 at 18:33
  • That doesn't work. the dot isn't respected by the convention plugin's URL to Resource mapping. ( There is a way to change the '-' to another character but that path doesn't seem promising. ) Additionally, if the source file is still not a .js, then it seems like a hassle for various tools. I'm trying to preserve the .js on the actual file more than the URL; though that could change if I encounter browser specific issues with the URL. – chad Nov 08 '12 at 18:57
  • are you trying to make `src="dynamic-javascript-file"` literal? – Jaiwo99 Nov 08 '12 at 20:12
  • 1
    What do you mean by literal? It's never going to be "literal" because it's going through the Struts 2 mappings, but I would like it to appear to be a real file . . . so, "dynamic-javascript-file.js" would be nice . . . somehow struts 2 would have to handle the incoming url, with the .js, as a url it should handle, and that would have to map to a physical file in the project that also had a .js ending, but the file would be processed as a template of some sort . . . – chad Nov 08 '12 at 20:37

0 Answers0