티스토리 뷰
728x90
출처
- [스프링부트 6] Spring MVC View 만들기 (JSP) - 내. 일. 을 바꾸는 업무 자동화
- [SpringBoot] 스프링부트를 사용해서 웹 서버 기본 틀 만들기 - 밥대장
Maven pom.xml 설정
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.31</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
Spring Boot JSP ViewResolver 구성
JSP 파일 위치를 해결하려면 두 가지 방법을 사용할 수 있습니다.
1) application.properties에 항목 추가
#http port
server.port=7070
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
2) JSP 페이지를 제공하도록 InternalResourceViewResolver 구성
package com.bluexmas.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan
public class MvcConfiguration extends WebMvcConfigurerAdapter
{
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
registry.viewResolver(resolver);
}
}
Controller 소스
package com.bluexmas.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class SampleController {
/*
* 스프링부트에서의 jsp 호출 테스트
*/
@RequestMapping("/jspSample")
public String jspSample(ModelMap modelMap) throws Exception {
modelMap.put("name", "홍길동");
List jspSample = new ArrayList();
jspSample.add("국어 : 100점");
jspSample.add("수학 : 90점");
jspSample.add("영어 : 75점");
modelMap.put("list", jspSample);
return "jspSample";
}
}
View(JSP) - src\main\webapp\WEB-INF\jsp\jspSample.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta charset="UTF-8">
<title>JSP Sample Page</title>
</head>
<body>
<div>[${name}]님의 시험성적입니다.</div>
<c:forEach var="item" items="${list}">
${item} <br />
</c:forEach>
</body>
</html>
실행
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Delphi
- MySQL
- oracle
- sas2009
- Mac
- koba2010
- 레이싱모델 익스트림 포토 페스티벌
- Linux
- Spring MVC
- SAS
- BPI-M4
- 일본여행
- 튜닝쇼 2008
- Java
- ffmpeg
- 동경
- Spring
- 전예희
- Delphi Tip
- android
- 송주경
- NDK
- ble
- JavaScript
- ubuntu
- flex
- KOBA
- Xcode
- 지스타2007
- 서울오토살롱
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함