admin管理员组文章数量:1279212
In a Spring MVC app, what is the best approach for putting external JavaScript files in WEB-INF/ along with jsps?
/WEB-INF/spring/foo.jsp which has an include of
<script src="foo.js"></script>.
I want foo.js in the WEB-INF/spring/ directory right beside the owning jsp?
I've noticed Spring has a ResourceSerlvet, but I'm not sure if that is the way to do this...
In a Spring MVC app, what is the best approach for putting external JavaScript files in WEB-INF/ along with jsps?
/WEB-INF/spring/foo.jsp which has an include of
<script src="foo.js"></script>.
I want foo.js in the WEB-INF/spring/ directory right beside the owning jsp?
I've noticed Spring has a ResourceSerlvet, but I'm not sure if that is the way to do this...
Share Improve this question edited Apr 21, 2009 at 13:54 TStamper 30.4k10 gold badges68 silver badges73 bronze badges asked Apr 21, 2009 at 13:50 HenryHenry1 Answer
Reset to default 9There is no need to place the javascript files under WEB-INF. You can have a structure like the following in your WAR file:
.
js/
images/
WEB-INF/
WEB-INF/jsp
Jsp files under WEB-INF\jsp will usually appear in the main context of the application, so the following will work
<script type="text/javascript" src="js/foo.js">
If you do want to place them under WEB-INF you need to add another layer to serve them. Probably the easiest way is to use JSP include tags:
<%@include file='js/foo.js'%>
This will copy the entire contents of the file to the generated html. You could also serve the javascript file directly by using the appropriate mappings and setting the content type.
本文标签: Spring MVC JavaScriptStack Overflow
版权声明:本文标题:Spring MVC JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741251455a2365867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论