问题
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