반응형
①
정적 리소스( html,css,js,img 등 ) ②
기본 매핑 값 <resources mapping="/resource/**" location="/resources/" />WEB-INF/spring/appServlet/servlet-context.xml에 아래 코드를 추가한다.
<resources mapping="/css/**" location="/resources/css/" /> <resources mapping="/js/**" location="/resources/js/" />
JSTL
<script src="<c:url value="/resources/js/test.js"/>"</script> !-- 절대 경로 지정(contextPath) --> <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/test.css">
java
<script src="/resources/js/test.js"/> <!-- 절대 경로 지정(contextPath) --> <% String cPath=request.getContextPath(); %> <link rel="stylesheet" href="<%=cPath %>/resource/css/test.css" />
컨트롤러 URL 에 따라 상위 경로를 통한 참조인지 현재 경로에서 시작되는 참조인지 구분하기 위해
contextPath를 사용한다.
반응형
'프로그래밍 > 웹' 카테고리의 다른 글
Spring MVC 개발 프로세스 (0) | 2021.01.31 |
---|---|
JSTL과 EL 사용하기 (0) | 2021.01.30 |
스프링 STS 프로젝트 배포하기 (0) | 2021.01.11 |
스프링 STS4 설치 및 프로젝트 생성 (0) | 2021.01.10 |
HTML Application - hta (0) | 2020.12.24 |