이번에 작성할 코드는 회원가입 페이지로 이동하는 버튼입니다.
사용자가 "회원가입" 버튼을 클릭하면 /register 경로로 이동해 회원가입 폼을 열 수 있도록 합니다.
이 버튼 코드는 login.html 파일 안에 추가합니다.
▼ Code
Path: templates/login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>로그인</title>
<style>
body {
margin: 40px;
}
form {
max-width: 350px;
margin: auto;
}
.row {
display: flex;
margin-bottom: 8px;
}
label {
width: 90px;
text-align: right;
margin-right: 8px;
}
input {
flex: 1;
}
.btns {
text-align: right;
margin-top: 10px;
}
</style>
</head>
<body>
<h2 style="text-align:center;">로그인</h2>
<div th:if="${error}" style="color:red; text-align:center;" th:text="${error}"></div>
<form th:action="@{/login}" method="post">
<div class="row">
<label for="id">ID:</label>
<input type="text" id="id" name="id" required>
</div>
<div class="row">
<label for="password">비밀번호:</label>
<input type="password" id="password" name="password" required>
</div>
<div class="btns">
<button type="submit">로그인</button>
<button type="button" onclick="location.href='/register'">회원가입</button>
</div>
</form>
</body>
</html>▼ Explain
<button type="button"> 일반 버튼을 의미합니다. type="button"은 폼 전송 기능이 없는 단순 클릭 버튼입니다. 클릭 시 지정된 자바스크립트 동작을 수행합니다. onclick="location.href='/register'" 버튼을 클릭했을 때 실행할 동작을 지정합니다. location.href는 브라우저의 주소를 변경하는 속성입니다. http://localhost/register 주소로 이동하라는 뜻입니다. 클릭하면 회원가입 페이지(/register)로 이동합니다.
개인정보처리방침 · 이용약관