이제 회원가입 기능을 만듭니다.
먼저 로그인 페이지에 회원가입 버튼을 추가합니다.
▼ Code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>로그인</title>
<link rel="stylesheet" href="/static/common.css" />
</head>
<body>
<h2>로그인</h2>
<form method="post">
<input name="userid" placeholder="아이디" required />
<br />
<input name="pwd" type="password" placeholder="비밀번호" required />
<br />
<button type="submit">로그인</button>
<button type="button" onclick="location.href='/member/register'">회원가입</button>
</form>
<% if (typeof msg !== 'undefined' && msg === 'fail') { %>
<p style="color: red">로그인에 실패했습니다.</p>
<% } else if (typeof msg !== 'undefined' && msg === 'logout') { %>
<p style="color: red">로그아웃이 완료되었습니다.</p>
<% } %>
</body>
</html>
▼ Explain
<button type="button"> 폼(form)을 전송하지 않고 단순히 특정 동작(페이지 이동)을 수행하도록 지정하는 버튼입니다. onclick="location.href='/member/register'" JavaScript를 사용하여 페이지 이동을 수행합니다. 버튼을 클릭하면 브라우저의 주소가 /member/register로 변경됩니다. 서버에 정의된 회원가입 라우터(MemberService.js의 /register)가 실행됩니다.
개인정보처리방침 · 이용약관