Spring Boot 시작하기
- #8. Srping Boot JSP view 설정하기
이번 장은 JSP 파일들을 연결 할 수 있는 방법을 알아 보겠습니다. viewer 의 연결은 여러가지 방법( thymeleaf, velocity 등등 )이 있으나 사용해 보지 않은 관계로 JSP viewer 로 연결토록 하겠습니다.
spring-boot-starter-web 에 포함된 tomcat 은 JSP 엔진을 포함하고 있지 않습니다.
pom.xml 에 아래 내용 추가.
1 2 3 4 5 6 7 8 9 | < dependency >
< groupId >javax.servlet</ groupId >
< artifactId >jstl</ artifactId >
</ dependency >
< dependency >
< groupId >org.apache.tomcat.embed</ groupId >
< artifactId >tomcat-embed-jasper</ artifactId >
</ dependency >
|
위와 같이 jasper 와 jstl 을 의존성에 포함시켜줘야 JSP파일의 구동이 가능합니다.
application.properties 에 아래 내용 추가.
1 2 | spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
|
jsp 파일은 Springboot 의 templates 폴더안에서 작동하지 않습니다.
/webapp/WEB-INF/jsp 폴더를 만든 다음 jsp 파일들을 넣어야됩니다.
그럼 이제 controller 와 jsp 파일을 설정해 보겠습니다.
JspViewTestController.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class JspViewTestController {
@RequestMapping (value= "/" )
public String root() {
return "viewtest" ;
}
@RequestMapping (value= "/test" )
public String test() {
return "test/test2" ;
}
}
|
/WEB-INF/jsp/viewtest.jsp
/WEB-INF/jsp/test/test2.jsp
위 파일들에 내용은 임의로 작성해주시면 됩니다.

위와 같이 설정해 주시면 됩니다.
http://localhost
http://localhost/test
를 하시면 jsp 파일들이 열리는 것을 확인하실수 있습니다.
다음으로 ModelAndView 설정을 알아보겠습니다.