I am fairly new to spring and I am having issues with accessing my resources in my Spring mvc app. I have tried Google and using stack overflow to find an answer (none of th
Set the resource order as below
<mvc:resources mapping="/resources/**" location="/resources/" order="-1"/>
Instead of mixing JSTL and JSP EL, you can configure spring like this :
<mvc:resources mapping="/resources/**" location="/WEB-INF/pages/" />
in your case,in the JSP use the following :
<link href="<c:url value="/resources/My_CSS.css"/>" rel="stylesheet"/>
You should place all of your static web content such as images, css and javascript in a resources directory under the webcontent (root directory) directory.
Then in myServlet-servlet.xml
specify the directory as a resources directory. This will tell the dispatcher not to process requests for static resources.
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
In your jsp files you should then access these resources using a root relative url that relies upon the context path resolved by JSP EL.
<link href="${pageContext.servletContext.contextPath}/resources/My_CSS.css" rel="stylesheet"/>
In your jsp file you should set,
<c:set var="context" value="${pageContext.request.contextPath}" />
and your resource files js, css, img etc. include them with,
<script src="${context}/resources/your.file.js" type="text/javascript"></script>
<link href="${context}/resources/your.min.css" rel="stylesheet" type="text/css"/>
Also you should use this before href to controller links, like
<a href="${context}/yourPage">
In this way you can use context path that is defined in servlet container or app server Tomcat, jetty etc.
When using this:
<mvc:resources mapping="/resources/**" location="/META-INF/RESOURCES/" />
use this code in jsp :
<link href="<c:url value="/"/>resources/My_CSS.css" rel="stylesheet"/>
Look the difference. CAPS RESOURCES locates file path. and resources locates in web path