티스토리 뷰
* 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>
<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");
}
%>
<%
// 로그인 정보 설정
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>
<%
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.invalidate(); // 세션 삭제
response.sendRedirect("./main.jsp");
%>
session의 유효 시간은 기본적으로 30분이다
'개발 > 개발 자료' 카테고리의 다른 글
(IOS) View Life Cycle (0) | 2016.03.02 |
---|---|
(JSP)gmail smtp서버를 이용하여 메일보내기 (0) | 2016.03.01 |
(Android) 화면 가로/세로 Layout 다르게 주기 (0) | 2016.02.19 |
(Android) TextView를 상속받아 글자 테두리 효과 추가하기 (1) | 2016.02.11 |
(Android) 간단하게 TextView에 테두리 주기 (0) | 2016.02.11 |
댓글