컨트롤러 생성하기
com.app.app.Controller 패키지에 AppController 클래스를 생성해준다.
package com.app.app.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.app.app.HomeController;
@Controller
public class AppController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
}
view 만들기
src - main - webapp - WEB-INF - views 에 index.jsp를 생성한다
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<table border="1" align="center" width="500" height="200">
<tr>
<td colspan="4" height="100" align="center">Main page</td>
</tr>
<tr>
<td colspan="2" align="center" width="250"><a href="Login">로그인</a></td>
<td colspan="2" align="center" width="250"><a href="Register">회원가입</a></td>
</tr>
</table>
</body>
</html>
위와 같이 입력한다.
Register.jsp를 생성한다.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원가입</title>
</head>
<body>
<form name="Register" method="post" action="RegisterAct">
<table border="1" align="center" width="500" height="500">
<tr>
<td colspan="4" height="100" align="center">회원가입</td>
</tr>
<tr>
<td colspan="1" height="100" align="center">ID</td>
<td colspan="3" height="100" align="center">
<input type="text" name="user_id">
</td>
</tr>
<tr>
<td colspan="1" height="100" align="center">Password</td>
<td colspan="3" height="100" align="center">
<input type="text" name="password">
</td>
</tr>
<tr>
<td colspan="1" height="100" align="center">NickName</td>
<td colspan="3" height="100" align="center">
<input type="text" name="nickname">
</td>
</tr>
<tr>
<td colspan="1" height="100" align="center">Name</td>
<td colspan="3" height="100" align="center">
<input type="text" name="name">
</td>
</tr>
<tr>
<td colspan="4" height="100" align="center"><input type = "submit" value="가입하기"></td>
</tr>
</td>
</tr>
</table>
</form>
</body>
</html>
Login.jsp 도 생성해 준다.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<form name="Login" method="post" action="LoginAct">
<table border="1" align="center" width="500" height="400">
<tr>
<td colspan="4" height="100" align="center">로그인</td>
</tr>
<tr>
<td colspan="2" align="center" width="250">아이디</td>
<td colspan="2" align="center" width="250"><input type="text" name="id"></td>
</tr>
<tr>
<td colspan="2" align="center" width="250">비밀번호</td>
<td colspan="2" align="center" width="250">
<input type="text" name="password">
</td>
</tr>
<tr>
<td colspan="4" align="center" width="250">
<input type="submit" value="로그인">
</td>
</tr>
</table>
</form>
</body>
</html>
View에 URL을 매핑하기
AppController를 수정 해 준다
package com.app.app.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class AppController {
private static final Logger logger = LoggerFactory.getLogger(AppController.class);
@RequestMapping("/")
public String index(Model model) {
return "index";
}
@RequestMapping("/Register")
public String Register(Model model) {
return "Register";
}
@RequestMapping("/Login")
public String Login(Model model) {
return "Login";
}
}
위 코드는 각각 index.jsp, Register.jsp, Login.jsp를 /, /Register, /Login 의 url에 매핑해주는 코드이다.
서버를 실행하고 http://localhost:8080/app/ 으로 접속해보자.
아래와 같이 나온다면 잘 따라온 것이다.
'WEB > Spring' 카테고리의 다른 글
6) Spring - 로그인(Session 이용) (0) | 2019.10.08 |
---|---|
5) Spring - 회원가입(ajax를 이용한 id 중복체크) (2) | 2019.10.08 |
4) Spring - 회원가입 처리하기. (0) | 2019.09.26 |
2) Spring - 기본설정(MyBatis) (0) | 2019.09.25 |
1) Spring - STS 설치하기. (0) | 2019.09.25 |