TIL # 2022.11.29

kdobro_dev·2022년 11월 29일
0

TIL (Today I Learned)

목록 보기
52/56
post-thumbnail

Java Spring boot JSP 연동

application.properties

server.port = 8081 // 서버 포트를 지정해주지 않으면 8080이다. 

spring.datasource.driver=com.mysql.cj.jdbc.Driver
spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/myDBName?&serverTimezone=UTC&autoReconnect=true&allowMultiQueries=true&characterEncoding=UTF-8
spring.datasource.username=myid // DB 계정 ID
spring.datasource.password=**** // DB 계정 password
spring.datasource.mapper-locations=classpath:/mapper/**/*.xml // mapper 파일 경로 지정

spring.mvc.view.prefix=/WEB-INF/views/ // .jsp 파일 경로
spring.mvc.view.suffix=.jsp

build.gradle

implementation 'org.apache.tomcat.embed:tomcat-embed-jasper' // 내장 톰켓 사용
implementation 'javax.servlet:jstl' // jstl 사용

Controller 생성

package com.myweb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {
	
	@RequestMapping("/")
	public String hello() {
		return "main"; // index 파일을 리턴한다.
	}
}

jsp 파일 생성

src/main/webapp/WEB-INF/views/main.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
Main Page
</body>
</html>

서버 실행 포트(8081)

profile
do your best at any moment

0개의 댓글