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

时光总嘲笑我的痴心妄想 提交于 2019-12-12 04:03:35

问题


I am developing Spring web application. my application package structure is

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

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.

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.


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/18571955/how-to-give-path-for-external-javascript-file-inside-web-inf-in-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!