기록

Spring/Jsp 사용설정 본문

Web/Spring

Spring/Jsp 사용설정

youngyin 2022. 10. 24. 10:00

프로젝트 생성

파일구조

build.gradle

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    // jsp
    implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
    implementation 'javax.servlet:jstl'
}

HomeController

@Controller
public class HomeController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(){
        return "index";
    }
}

application.properties

spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp

#JSP수정시 서버 재시작없이 바로 적용될 수 있게 설정
server.servlet.jsp.init-parameters.development=true

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h1>hello</h1>
</body>
</html>

결과

Comments