본문 바로가기
테크/기타

spring boot과 jsp 기본 프로젝트(웹)

by ahnne 2017. 8. 30.


# spring boot 에서 jsp를사용하려면, 몇가지 dependency 설정과 경로설정이 필요하다.


# spring starter project 생성 + web 항목 선택


# pom dependency

(생략)


<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>


<!-- for using jsp -->

<dependency>

<groupId>org.apache.tomcat.embed</groupId>

<artifactId>tomcat-embed-jasper</artifactId>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

</dependency>

<dependency>

<groupId>org.eclipse.jdt.core.compiler</groupId>

<artifactId>ecj</artifactId>

<version>4.6.1</version>

<scope>provided</scope>

</dependency>


</dependencies>


(생략)


# application.properties

spring.mvc.view.prefix=/WEB-INF/jsp/

spring.mvc.view.suffix=.jsp 


# controller

@Controller

public class TestController {

@RequestMapping("/test")

public String test(HttpServletRequest request, HttpServletResponse response) {

return "test";

}


# project structure

 



# test.jsp

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

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

test page

</body>

</html>