STS Spring MVC: how to include JS file in JSP

I installed SpringSource Tool Suite 2.8.0. I am trying to include a JS file in a JSP using the Spring MVC template as a starting point. My JSP looks like this:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
    <title>Home</title>
    <script type="text/javascript" src="/a.js"></script>
</head>
<body>
    Hello world!  
</body>
</html>

a.js is under src \ main \ resources and looks like this:

window.alert("A");

The result is "Hello world!" printed without warning: - (

I tried to put the JS file in different places by changing src with / without "/" and even adding the servlet mapping in web.xml to use the default servlet for "* .js". Nothing is working.

What am I doing wrong?

+5
source share
2 answers

js .war ? js css src/main/webapp. - src/main/webapp/js src/main/webapp/css.

-, , c: url, , .

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

firebug chrome, , 404 a.js , .

+3

js webapp. ( webapp/resources/js)

, mvc: resources:

URL- , ResourceHttpRequestHandler . , -, . cache-period (1 - , YSlow), . Last-Modified ( ), 304 , , . , URL- /resources/ ** , :

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

: Spring

+3

All Articles