☠️ Java
Spring Tool Suite 4 & Dynamic Web Project
James Wetzel
2024. 11. 12. 15:55
728x90
반응형
1. Spring Starter Project
Spring Starter Project 생성합니다.
Spring Web
Spring Boot DevTools
2. pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
tomcat-embed-jasper 의존성에 역할은 다음과 같다.
스프링 부트 앱에는 톰캣 서버가 내장되어 있다.
톰캣 서버는 servlet container 이다.
톰캣 서버는 servlet을 실행하는 서버이다.
톰캣에서 JSP 파일은, 먼저 servlet이로 변환(컴파일)된 후 실행된다.
tomcat-embed-jasper는 JSP 파일을 servlet으로 변환하는 컴파일러이다.
이 것을 프로젝트에 추가하지 않고 실행하면, JSP 파일이 실행되지 않고, 웹브라우저에서 다운로드 될 것이다.
톰캣은 servlet만 실행할뿐, 다른 파일들은 웹브라우저로 그대로 전송하기 때문이다
3. Dynamic Web 폴더
webapp/WEB-INF/view 폴더를 각각 생성합니다.
4. application.properties 설정
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
5. Eclipse Marketplace
Eclipse Enterprise Java and Web Developer Tools 를 설치합니다.
6. controller & index.jsp
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/index")
public class HomeController {
@GetMapping
public void index() { }
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
this is my index.jsp
</body>
</html>
7. 호출
http://localhost:8080/
728x90
반응형