티스토리 뷰


* login.jsp


<%@ page contentType="text/html;charset=EUC-KR"%>
<html>
  <body onload="login.id.focus()">
  
  <form name="login" action="loginProc.jsp" method="post">
    
      아이디 : <input type="text" name="id" size="8" maxlength="8"/><p>
      비밀번호 : <input type="password" name="pwd" size="8" maxlength="8"/><p>
      <input type="submit" value="로그인"/>
      <input type="reset" value="취소"/>
  </form>
  
  </body>
</html>


* loginProc.jsp

<%@ page contentType="text/html;charset=EUC-KR"%>

<%
    // 로그인 정보 설정
    String userID="id";
    String userPWD="pwd";
    String userName="이름";
    
    // login.jsp로부터 form data를 받는다
    String id = request.getParameter("id");
    String pwd = request.getParameter("pwd");
    
    // id, pwd가 맞을 경우 실행
    if(userID.equals(id) && userPWD.equals(pwd)) 
    {
        session.setAttribute("s_Name",userName);
        session.setAttribute("s_Id", userID);
        response.sendRedirect("./main.jsp"); // main.jsp 에 session 정보를 보낸다
    }
    else
    {
        response.sendRedirect("./main.jsp");
    }
%>


* main.jsp

<%@ page contentType="text/html;charset=EUC-KR"%>

<%
    String checkName = "";
    String checkId = "";
    
    
    checkName = (String)session.getAttribute("s_Name");
    
    if(checkName == null)
    {
        response.sendRedirect("./login.jsp");
    }
    
    checkId = (String)session.getAttribute("s_Id");
%>

<html>
    <body>
        세션 인증 성공 <br><br>
        <%=checkName%>(<%=checkId%>)님 안녕!!<br>
        <a href="logout.jsp">로그아웃</a>
    </body>
</html>


* logout.jsp

<%@ page contentType="text/html;charset=EUC-KR"%>

<%
    session.invalidate(); // 세션 삭제
    response.sendRedirect("./main.jsp");
%>

session의 유효 시간은 기본적으로 30분이다

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함