如何在JSP中为WEB-INF内的外部javascript文件提供路径 [英] How to give path for external javascript file inside WEB-INF in JSP
问题描述
我正在开发Spring Web应用程序. 我的应用程序包结构是
I am developing Spring web application. my application package structure is
web/----|
|WEB-INF/
|-jsps/
|-scripts/
|-styles/
|-web.xml
是Spring MVC
&基于maven
的项目.我必须在jsp
文件中使用外部javascript
文件.
如果我使用<script src="/scripts/MyFile.js"/>
则无法正常工作,因为资源位于WEB-INF
内部.
我已经尝试了很多方法,但是找不到解决方案.
所以,请您告诉我如何从JSP
文件访问external javascript
文件.
It is Spring MVC
& maven
based project. I have to use the external javascript
file in jsp
file.
if I use <script src="/scripts/MyFile.js"/>
is not working as the resource is inside WEB-INF
.
I have tried so many ways but I could not find solution.
So could you please tell me how to access external javascript
file from JSP
file.
注意:我无法更改Directory Structure
的规格.而且我应该只使用外部javascript文件.
Note: I cant change my Directory Structure
as it is specification. And I should only use external javascript files.
所以,请您提供解决方案.谢谢.
So could you please provide solution. Thanks in adavnce.
推荐答案
You can configure (see: here):
<mvc:resources mapping="/scripts/**" location="/WEB-INF/scripts/" />
然后像这样引用它:
<script type="text/javascript" src="${context}/scripts/MyFile.js"></script>
这篇关于如何在JSP中为WEB-INF内的外部javascript文件提供路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!