Spring - 기초편2
1) 파일 이름 : 02-SpringMethod
2) 앞에서 사용한 기본적인 파일
1. com.heeyeon.config -> package
① . RootAppContext.java
② . ServletAppContext.java
③ . SpringConfigClass.java
2. com.heeyeon.controller -> package
① . HomeController.java
3) 파일 자체에 pom.xml 넣기
-----------------------------------------------------------------------------------------------------------
1) TestController.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package com.heeyeon.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class TestController {
@RequestMapping(value="/Test01.do", method=RequestMethod.GET)
public String test01() {
return "test01";
}
@RequestMapping(value="/Test02.do", method=RequestMethod.POST)
public String test02() {
return "test02";
}
@RequestMapping(value="/Test03.do", method=RequestMethod.GET)
public String test03() {
return "test03";
}
@RequestMapping(value="/Test04.do", method=RequestMethod.POST)
public String test04() {
return "test04";
}
@GetMapping("/Test05.do")
public String test05() {
return "test05";
}
@PostMapping("/Test06.do")
public String test06() {
return "test06";
}
@RequestMapping(value="/Test07.do", method= {RequestMethod.GET, RequestMethod.POST})
public String test07() {
return "test07";
}
}
|
cs |
-----------------------------------------------------------------------------------------------------------
1 ) test01.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ 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>
<h1>test01</h1>
</body>
</html>
|
cs |
2 ) test02.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ 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>
<h1>test02</h1>
</body>
</html>
|
cs |
3 ) test03.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ 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>
<h1>test03</h1>
</body>
</html>
|
cs |
4 ) test04.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ 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>
<h1>test04</h1>
</body>
</html>
|
cs |
5 ) test05.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ 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>
<h1>Get Mapping으로 넘긴 test05.jsp입니다.</h1>
</body>
</html>
|
cs |
6 ) test06.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ 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>
<h1>PostMapping으로 넘겨진 test06.jsp입니다.</h1>
</body>
</html>
|
cs |
7 ) test07.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ 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>
<h1>test07</h1>
</body>
</html>
|
cs |
-----------------------------------------------------------------------------------------------------------
→ index.jsp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<%@ 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>
<ul>
<!-- a태그는 get방식으로 요청 처리 -->
<li><a href="Test01.do">Test01-Get</a></li>
</ul>
<hr>
<form method="POST" action="Test02.do">
<button type="submit">submit</button>
<!-- <input type="submit" value="나도 submit"> -->
</form>
<hr>
<form method="GET" action="Test03.do">
<button type="submit">GET으로 요청 === @RequestMapping (value="/Test03" , method=RequsetMethod.GET))</button>
</form>
<hr>
<form method="POST" action="Test04.do">
<button type="submit">POST로 요청 === @RequestMapping (value="/Test04" , method=RequsetMethod.POST)</button>
</form>
<hr>
<form method="GET" action="Test05.do">
<button type="submit">GET으로 요청 (@GetMapping("/Test05"))</button>
</form>
<hr>
<form method="POST" action="Test06.do">
<button type="submit">POST로 요청(@PostMapping("/Test06"))</button>
</form>
<hr>
<form method="GET" action="Test05.do">
<button type="submit">GET으로 요청 (@GetMapping("/Test07"))</button>
</form>
<hr>
<form method="POST" action="Test07.do">
<button type="submit">POST로 요청(@PostMapping("/Test06"))</button>
</form>
</body>
</html>
|
cs |
-----------------------------------------------------------------------------------------------------------
실행은 되지만 파일명에 도저히 왜 오류인지 모르겠는 ,, ㅋ
톰켓이 잘못된건가 몇몇의 파일만 저런다 ㅜ ㅜ 실행되니까 뭐
-----------------------------------------------------------------------------------------------------------
결과 화면