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

7.3k views Asked by At

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.

2

There are 2 answers

0
Moritz Petersen On

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>
0
Srikanth On

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.