스프링 공부할때 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/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<resource>
의 정체는 /resources/** 라는 요청이오면 /resources/ 경로로 잡아주라는 뜻이다.
그 아래 <beans>
의 의미는 뷰리졸버를 이용해서 반복잡업을 줄여준다. 매번 Controller에서 view로 이동할때 풀경로를 잡아주기 어려우니까 앞뒤를 픽스시켜 자동으로 매핑되도록 하는것이다. 따라서 컨트롤러에서 return "test"; 로만 적어도 된다.
오키오키 당연한 기초다
근데 전자정부프레임워크에서는 <mvc:resource>
를 더 많이 쓰나보다..(아닐지도) 그래서 찾아봤다.
<mvc:resources location="/resources/" mapping="/resources/**" cache-period="0" />
<mvc:resources location="/test/" mapping="/test/**" />
태그만 좀 다르고 내용은 똑같은것같다. 결국 똑같은 설명인데 더 멋지게 얘기하자면 location에 대한 요청이 들어오면 WAS의 DefaultServlet에 위임한다. 즉 모든 요청은 Spring MVC에 영향을 받아 직접접근이 불가능하므로 요청을 WAS로 하면서 URL을 통해 resource에 접근하는것이다!
http://localhost/test/hello.js 뭐 이런식으로 접근이 가능해진다는것...!!
DefaultServlet 설정파일은 tomcat기준으로 web.xml에서 볼 수 있다