spring에서 static 자원 사용하기 !

출처 : http://stackoverflow.com/questions/1483063/spring-mvc-3-and-handling-static-content-am-i-missing-something


[핵심 요약]

servlet-context.xml

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->

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


test.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<h1>Page with image</h1>
<!-- use c:url to get the correct absolute path -->
<img src="<c:url value="/resources/img/image.jpg" />" />


위와 같이 서블릿 설정에서 고정자원 경로를 설정한 이후 VIEW에서 c:url 을 활용하면 된다.

(그냥 링크 대신 c:url을 활용하면 해당 app name (배포 경로)가 포함되기 때문에 link오류가 발생하지 않음.)



+ Recent posts