如何在JSP中为WEB-INF内的外部javascript文件提供路径 [英] How to give path for external javascript file inside WEB-INF in JSP

查看:156
本文介绍了如何在JSP中为WEB-INF内的外部javascript文件提供路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆