티스토리 뷰

휴지통/JSP

session

LeReve 2013. 5. 27. 18:17

 

sessionT1.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>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<%--sessionT1.jsp --%>
<body>
 <p>
  <b>안녕하세요. jsp홈페이지입니다.<br>
   사이트에 접속하기 위해서는
   사용자 인증과정이 필요합니다.<br>
  </b>
 </p>
 <p>
  <b>ID와 Password를 입력하세요.</b>
 </p>
 <center>
 <form action="sessionT2.jsp" method="post"> <%-- get하면 password가 url로 다 보여진다 --%> 
 <table width="350" border="1" cellpadding="0" cellspacing="0"
     bordercolor="#000000">
  <tr>
   <td bgcolor="#ff9999" width="25%">I D</td>  
   <td width="75%">
    <input type="text" name="id">
   </td>  
  </tr>
  <tr>
   <td bgcolor="#ff9999" width="25%">Password</td>  
   <td width="75%">
    <input type="password" name="pass">
   </td>  
  </tr>
  <tr>
   <td colspan="2">
    <input type="submit" value="로그인">
    <input type="reset" value="취소">
   </td>  
  </tr>
 </table>
 </form>
 </center>
</body>
</html>

 

 

 

sessionT2.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>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>사용자인증처리</title>
</head>
<%--sessionT2.jsp --%>
<%
 //로그인해서 t4로 갔
 //현 페이지에 대한 브라우저 캐시를 사용하지 않겠음
 response.setDateHeader("Expires", 0);
 response.setHeader("Pragma", "no-cache");//http 1.0   
 if(request.getProtocol().equals("HTTP/1.1")){
  response.setHeader("Cache-Control", "no-cache");//http 1.1
 }
%>
 <%
  //DataBase가정
  String did[] = {"gildong","lime","juwon"};
  String dpass[] = {"1234","9999","8888"};
  
  //폼입력받은 id,pass
  //request.setCharacterEncoding("euc-kr");//getParameter가 한글일 경우
  String id = request.getParameter("id");//sessionT1의 form에 있는 name과 일치하게
  String pass = request.getParameter("pass");
  
  boolean dflag = false;
  
  for(int i=0; i<did.length; i++){
   if(id!=null&&id.equals(did[i])){//일치하는 id를 찾았다
    //앞에가 false나오면 &&뒤에는 실행 안한다.
    if(pass!=null&&pass.equals(dpass[i])){//pass가 일치한다면
     //로그인 성공
     session.setAttribute("login", "success");//세션로그인
     dflag = true;
     break;
    }//else{
     //로그인 실패(id일치, pass불일치)
    //}
   }
  }//for
  if(!dflag){//if(dflag==false){로그인 실패
   response.sendRedirect("sessionT1.jsp");//로그인페이지이동
  }
 %>
<body>
 <p><b>사용자인증완료</b></p>
 <a href="sessionT3.jsp">서비스페이지이동</a>
</body>
</html>

 

 

 

sessionT3.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>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>서비스페이지</title>
</head>
<%--sessionT3.jsp --%>
<%
 //로그인해서 t4로 갔
 //현 페이지에 대한 브라우저 캐시를 사용하지 않겠음
 response.setDateHeader("Expires", 0);
 response.setHeader("Pragma", "no-cache");//http 1.0   
 if(request.getProtocol().equals("HTTP/1.1")){
  response.setHeader("Cache-Control", "no-cache");//http 1.1
 }
%>
<body>
 <center>
 <p><b>이 페이지는 사용자 인증을 받아야 볼 수 있습니다.</b></p>
 <%
  String login = (String)session.getAttribute("login");
  
  if(login==null||!login.equals("success"))
   response.sendRedirect("sessionT1.jsp");
  
 %>
 <%--<img src="../img/girl.jpg" width="500" height="600"> --%>
 <%--<img src="http://localhost:8080/TomTest2/img/girl.jpg" width="500" height="600"> --%>
 <img src="/TomTest2/img/girl.jpg" width="500" height="600"><%--/는 localhost:8080까지 --%>
 
 <br>
 감사합니다.<br>
 <a href="sessionT4.jsp">로그아웃</a>
 </center>
</body>
</html>

 

 

 

sessionT4.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>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<%--sessionT4.jsp --%>
<body>
<%
 session.invalidate();//세션(연결)종료
%>
 <p><b>세션이 종료되었습니다.</b></p>
 <a href="sessionT3.jsp">서비스페이지로 이동</a>
</body>
</html>

 

 

'휴지통 > JSP' 카테고리의 다른 글

context_test  (0) 2013.05.27
session내장객체  (0) 2013.05.24
context_test  (0) 2013.05.24
JSP 내장객체(내장변수,기본객체)  (0) 2013.05.24
config, application  (0) 2013.05.24
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/09   »
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
글 보관함