简体   繁体   English

如何在JSP中为WEB-INF内的外部javascript文件提供路径

[英]How to give path for external javascript file inside WEB-INF in JSP

I am developing Spring web application. 我正在开发Spring Web应用程序。 my application package structure is 我的应用程序包结构是

web/----|
        |WEB-INF/
             |-jsps/
             |-scripts/
             |-styles/
             |-web.xml

It is Spring MVC & maven based project. 这是基于Spring MVCmaven的项目。 I have to use the external javascript file in jsp file. 我必须在jsp文件中使用外部javascript文件。 if I use <script src="/scripts/MyFile.js"/> is not working as the resource is inside WEB-INF . 如果我使用<script src="/scripts/MyFile.js"/>不能正常工作,因为该资源位于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. 所以,请您告诉我如何从JSP文件访问external javascript文件。

Note: I cant change my Directory Structure as it is specification. 注意:我无法更改Directory Structure因为它是规范。 And I should only use external javascript files. 而且我应该只使用外部javascript文件。

So could you please provide solution. 所以请您提供解决方案。 Thanks in adavnce. 非常感谢。

You can configure (see: here ): 您可以配置(请参阅: 此处 ):

<mvc:resources mapping="/scripts/**" location="/WEB-INF/scripts/" />

Then reference it like: 然后像这样引用它:

<script type="text/javascript" src="${context}/scripts/MyFile.js"></script>

Here is the Some other way: 这是另一种方式:

src="${pageContext.request.contextPath}/jscript/jquery/jquery-1.6.2.js"

We have been using this in our projects. 我们一直在项目中使用它。 Working perfectly. 工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM