<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>로그인 화면</title>
<style >
span{
color: red;}
</style>
<%
String result = (String) request.getAttribute("result");
if (result != null && result.equals("pw")) {
%>
<script>
window.onload = function(){
var sp = document.getElementById("errorSpan");
sp.innerHTML ="비밀번호가 틀렸습니다.";
}
</script>
<%
} else if (result != null && result.equals("id")) {
%>
<script>
window.onload = function(){
var sp = document.getElementById("errorSpan");
sp.innerHTML ="아이디가 없습니다..";
}
</script>
<%
}
%>
</head>
<body>
<form action="Loginprocess.jsp" method="post">
<table border="2px">
<tr>
<td colspan="2" align="center"><h2>로그인 화면</h2></td>
</tr>
<tr colspan="2">
<td><span id="errorSpan"></span></td>
</tr>
<tr>
<td>아이디</td>
<td><input type="text" size="20" name="id" /></td>
</tr>
<tr>
<td>비밀번호</td>
<td><input type="password" size="20" name="pw" /></td>
</tr>
<tr>
<td><input type="submit" value="로그인" /></td>
<td><input type="reset" value="취소" /></td>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>로그인 처리</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
out.println(id+" : " +pw);
if(id.equals("root") && pw.equals("system")){
request.setAttribute("id", id);
RequestDispatcher dispatcher =
request.getRequestDispatcher("result.jsp");
dispatcher.forward(request, response);
}else if(id.equals("root")){
request.setAttribute("result", "pw");
RequestDispatcher dispatcher =
request.getRequestDispatcher("login.jsp");
dispatcher.forward(request, response);
}else{
request.setAttribute("result", "id");
RequestDispatcher dispatcher =
request.getRequestDispatcher("login.jsp");
dispatcher.forward(request, response);
}
%>
</body>
</html>
20140916jsp.zip