admin管理员组

文章数量:1318564

I have a js file in the folder WebContent/resources/js/test.js. I am trying to include the same file in a jsp. But the jsp file is unable to find the js file (404 error in browser console). I have gone throw couple of questions in SO:

Can SpringMVC be configured to process all requests, but exclude static content directories?

Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP

STS Spring MVC: How to include a JS file in a JSP

But still not helping. Here goes my code:

In the application context, i am using the mvc:resource tag.

<mvc:resources mapping="/resources/**" location="/resources/" />

In my jsp

<script src="${contextPath}/resources/js/test.js" type="text/javascript"></script>

tried giving src value with

 <c:url> 

too.

my web.xml has

<servlet-mapping> 
<servlet-name>TestProject</servlet-name> 
<url-pattern>/</url-pattern>
</servlet-mapping>

Firebug says

The requested resource (/resources/js/test.js) is not available.

Any help would be appreciated.

UPDATE

The GET request URL in firebug is this

http://localhost:8080/TestProject/resources/js/test.js

Is it right??

I have a js file in the folder WebContent/resources/js/test.js. I am trying to include the same file in a jsp. But the jsp file is unable to find the js file (404 error in browser console). I have gone throw couple of questions in SO:

Can SpringMVC be configured to process all requests, but exclude static content directories?

Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP

STS Spring MVC: How to include a JS file in a JSP

But still not helping. Here goes my code:

In the application context, i am using the mvc:resource tag.

<mvc:resources mapping="/resources/**" location="/resources/" />

In my jsp

<script src="${contextPath}/resources/js/test.js" type="text/javascript"></script>

tried giving src value with

 <c:url> 

too.

my web.xml has

<servlet-mapping> 
<servlet-name>TestProject</servlet-name> 
<url-pattern>/</url-pattern>
</servlet-mapping>

Firebug says

The requested resource (/resources/js/test.js) is not available.

Any help would be appreciated.

UPDATE

The GET request URL in firebug is this

http://localhost:8080/TestProject/resources/js/test.js

Is it right??

Share Improve this question edited May 23, 2017 at 12:08 CommunityBot 11 silver badge asked Aug 14, 2012 at 12:23 shazinltcshazinltc 3,6667 gold badges38 silver badges49 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You need to do

<script src="<c:url value="/resources/js/test.js" />" type="text/javascript"></script>

Spring is trying to find the resource from the container context root, rather than the app context root.

本文标签: Spring 31 javascript file not found 404 errorStack Overflow