반응형
스프링에서 빈을 이용한 jsp 경로 설정 방법입니다.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- 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>
<context:component-scan base-package="com.myspring.pro27" />
</beans:beans>
bean을 이용하여 viewResolver 클래스의 속성을 위와 같이 설정해주시면 됩니다.
ModelAndView mav = new ModelAndView("home");
views로 기준으로 상대경로를 적어주시면 됩니다.
만약 views/list/home.jsp 라면 view의 경로는 /list/home입니다. 뒤에 jsp를 붙이시면 안됩니다.
반응형
'...' 카테고리의 다른 글
[Spring] 서블릿 컨테이너란? (0) | 2021.01.17 |
---|---|
[Spring] 스프링에서 환경 변수 사용하기 (0) | 2021.01.14 |
[Spring] log4j 이용하여 로그 출력하기 (0) | 2021.01.14 |
[Js] window.open 함수로 팝업창 열기 (0) | 2021.01.14 |
List cannot be resolved to a type 에러 (0) | 2021.01.12 |