🚙2022-08-17🚙
com.gyuone
└controller
└DemoController.java
package com.gyuone.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class DemoController { // 상위 패키지 밑으로 자동으로 들어가기
@ResponseBody
@RequestMapping("/")
public String home() {
return "Hello boot!!!";
}
@RequestMapping("/hello")
public String hello(Model model) {
model.addAttribute("message", "hello.jsp 입니다.");
return "hello";
}
}
└DemoApplication.java
package com.gyuone;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
└SevletInitializer.java
package com.gyuone;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
}
└staitc
└image
└love.png
└js
└script.js
function test(){
alert("JSP 테스트");
}
└view
└hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<%
request.setCharacterEncoding("UTF-8"); // 자바 소스 코드사용
%>
<!DOCTYPE html>
<html>
<head>
<script src="${contextPath}/js/script.js"></script>
<meta charset="utf-8">
<title>hello.jsp 페이지</title>
</head>
<body>
안녕하세요 <br>
<h2>${message}</h2>
<img width=200 height=600 src="${contextPath}/image/love.png" /> <br/>
<input type="button" name="테스트" value="테스트" onClick="test();">
</body>
</html>
└pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.gyuone</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
자체 내장된 톰캣 설정
'IT > WEB' 카테고리의 다른 글
[42일차] Spring 시험 (0) | 2022.08.19 |
---|---|
[41일차] Java Spring Boot (0) | 2022.08.18 |
[40일차] logback (0) | 2022.08.17 |
[40일차] 게시판 만들기(3) delete. update 추가 🌀 최종 게시판 만들기 (0) | 2022.08.17 |
[39일차] 게시판 만들기 (2) (0) | 2022.08.16 |
댓글