본문 바로가기

Java/Spring Boot

SpringBoot-003-Spring boot에서 JSP 사용하기

JSP 사용 설정

- Spring boot를 이용하는 경우 JSP가 아닌 템플릿을 이용

 

(1) application.properties 설정 변경

- src-main-webapp/WEB-INF/views 폴더 생성

- src/main/resources-application.properties에 다음을 추가

- prefix: 경로지정, suffix: 파일 확장자를 찾아줌

 

(2) build.gradle 설정 변경

- dependencies 부분에 JSP 사용 시 필요한 jstl 추가

- JSP 엔진 역할을 하는 tomcat-embed-jasper library 추가

1
2
3
4
5
6
7
8
dependencies {
    compile('javax.servlet:jstl')
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

(3) 저장 후 프로젝트 우클릭 - Gradle(STS) - Refresh Dependencies

 

(4) src/main/webapp/WEB-INF/views에서 JSP 파일을 만들어 사용

 

(5) Controller에서 다음과 같이 작성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package sample.conrtoller;
 
 
@Controller
public class HelloConrtoller {
    
    @RequestMapping("/index")
    public String hello() {
                
        return "index"//jsp file 명
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형