1. 로그인 창 만들기
- controller
package ex01;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/login2")
public class Login2 extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getRequestDispatcher("WEB-INF/jsp/member/login2.jsp").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String id = req.getParameter("id");
String pw = req.getParameter("pw");
req.setAttribute("id", id);
req.setAttribute("pw", pw);
req.getRequestDispatcher("WEB-INF/jsp/member/login2_result.jsp").forward(req, resp);
}
}
- 로그인 창 : login2.jsp
<%@ 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>
<script>
// 유효성 검증 예정
window.onload = function() {
document.frm.onsubmit = function() {
console.log(document.frm.id.value);
console.log(document.frm.pw.value);
console.log(document.frm.pwChk.value);
if(document.frm.id.value.length < 5) {
alert("아이디를 입력하세요")
return false;
}
else if(document.frm.pw.value !== document.frm.pwChk.value) {
alert("비밀번호 일치여부를 확인하세요")
return false;
}
}
}
</script>
</head>
<body>
<form name="frm" method="post">
<p>아이디 : <input name="id"></p>
<p>비밀번호 : <input type="password" name="pw"></p>
<p>비밀번호 확인 : <input type="password" name="pwChk"></p>
<button>로그인</button>
</form>
</body>
</html>
- 로그인 결과 : login2_result.jsp
<%@ 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>
<p>${id}</p>
<p>${pw}</p>
</body>
</html>
2. 로그인 창 실행하기