Reputation: 265
In Spring Petclinic the following tag is used for static content .
"<mvc:resources mapping="/resources/**" location="/resources/"/> "
But I am facing problems in understanding this because the mapping and the location are same . So what purpose will this tag solve ?If the css file request is like.
"spring:url value="/resources/css/petclinic.css" var="petclinicCss" "
then what would be the converted URL after mvc:resources tag has been executed .
Upvotes: 0
Views: 1084
Reputation: 43
As sayed, the "location" is where your files are and "pattern" the URL used to call them.
You will understand with this exemple. Suppose we have this WebContent folders structure :
-WebContent
-META-INF
-WEB-INF
-assets
-css
*myview.css
-js
-view
*myview.jsp //or html or any kind of view format)
now, in spring dispatcher I use the tag like this :
<mvc:resources mapping="/resources/**" location="/WEB-INF/assets/" />
then, in my "myview.jsp" to call "myview.css" i have to write this :
<link href="<c:url value="/resources/css/myview.css" />" rel="stylesheet" type="text/css">
In fact, what Spring dispatcher do is for all url starting with "/reources/", expressed by [mapping="/resources/**] (start with "resources" and ** means no matter the end) it replace the "/resources/" by "/WEB-INF/assets/" (configured by location="/WEB-INF/assets/") and append the rest of the url to "/WEB-INF/assets/" to fin the location of the resources in the project structure.
I hope it was clear now
Upvotes: 0
Reputation: 3475
<mvc:resources mapping="/resources/**" location="/resources/"/>
Any requests from this url pattern /resources/**
, Spring will look for /resources/
mapping
is url patternlocation
where the resources exists in project class-pathConfiguring Serving of Resources
Example usages,
By using JSTL <c:url>
<script type="text/javascript" src="<c:url value="/resources/js/jquery.js" />"></script>
By using <spring:url>
<spring:url value="/resources/images/favicon.ico" var="favicon" />
Upvotes: 3