페이지

2015. 1. 30.

[JSP] 게시판 로그인과 로그아웃

loginCheck.jsp


<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import = "bean.MemberDAO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>로그인 검증</title>
</head>

<body>
    <H1>로그인 검증 페이지</H1>
    <H2>loginCheck.jsp</H2>
   
    <%
    request.setCharacterEncoding("euc-kr");
    String id = request.getParameter("id");
    String pw  = request.getParameter("pw");
   
    MemberDAO dao = MemberDAO.getInstance();
    boolean check = dao.userCheck(id, pw);

    if(check==true){
        session.setAttribute("memId",id);
        response.sendRedirect("main.jsp");
    }else{ %>
    <script>
        alert("ID & PASSWORD를 다시 확인하세요.");
          history.go(-1);
    </script>
    <%}%>   
</body>
</html>


loginForm.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>로그인</title>
</head>
    <H1>로그인 페이지</H1>
    <H2>loginForm.jsp</H2>

<body onload="begin()">
    <form name="logincheckform" action="loginCheck.jsp" method="post" onSubmit="return checkIt()">
    <TABLE cellSpacing=1 cellPadding=1 width="260" border=1 align="center" >
        <TR height="30">
            <TD colspan="2" align="middle">
                <STRONG>회원로그인</STRONG>
            </TD>
        </TR>

        <TR height="30">
            <TD width="110" align=center>아이디</TD>
            <TD width="150"  align=center>
                <INPUT type="text" name="id" size="15" maxlength="12">
            </TD>
        </TR>
       
        <TR height="30">
            <TD width="110"  align=center>비밀번호</TD>
            <TD width="150"  align=center>
                <INPUT type=password name="pw"  size="15" maxlength="12">
            </TD>
        </TR>
       
        <TR height="30">
            <TD colspan="2" align="middle" >
                <INPUT type=submit value="로그인">
                <INPUT type=reset value="다시입력">
                <input type="button" value="회원가입" onclick="javascript:window.location='joinForm.jsp'">
            </TD>
        </TR>
    </TABLE>
    </form>
</body>

<script language="javascript">
<!--
    function begin(){
      document.logincheckform.id.focus();
    }
    function checkIt(){
      if(!document.logincheckform.id.value){
        alert("logincheckform : 아이디를 입력하지 않으셨습니다.");
        document.logincheckform.id.focus();
        return false;
      }
      if(!document.logincheckform.pw.value){
        alert("logincheckform : 비밀번호를 입력하지 않으셨습니다.");
        document.logincheckform.pw.focus();
        return false;
      }
    }
-->
</script>
</html>



logout.jsp

 <%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>로그아웃</title>
</head>
<body>
    <h1>로그아웃 페이지</h1>
    <h2>logout.jsp</h2>
  
    <%
    session.invalidate();
    response.sendRedirect("main.jsp");
    %>
</body>
</html>