Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 동기 부여
- 미래직장
- target
- 빈즈
- session.getAttribute
- 자바빈즈
- 페이지 이동
- "
- 팝업창
- scanner
- static
- BEANS
- ;
- 데이터사이언스
- session.setAttribute
- iframe
- session.removeAttribute
- Alert
- 영감
- 파일호출
- 동기부여
- opener
- javaBeans
- Import
- \
- 페이지이동
- 향상된 for문
- 버리자
- 파일 호출
- 로그인화면
Archives
- Today
- Total
갈림길 이정표
[JSP] Session test 본문
[session_test.html]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="session1.jsp" method="post">
id : <input type="text" name="id">
<input type="submit" value="로그인">
</form>
</body>
</html>
[session1.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
session.setAttribute("idKey", id); //session 속성은 어느 Servlet파일에서든 유효함 (request로 담으면 그 파일에서만 유효)
session.setMaxInactiveInterval(10);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>세션 연습</h2>
<form action="session2.jsp" method="post">
* 좋아하는 드라마는?<br>
<input type="radio" name="drama" value="악의 꽃" checked="checked">악의 꽃
<input type="radio" name="drama" value="비밀의 숲">비밀의 숲
<input type="radio" name="drama" value="모범형사">모범형사
<br>
<input type="submit" value="결과보기">
</form>
</body>
</html>
[session2.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
드라마 선택 결과<br>
<%
request.setCharacterEncoding("utf-8");
String drama = request.getParameter("drama"); //request
String myId = (String)session.getAttribute("idKey"); //session은 어디서든 부를 수 있음 (단, casting 필!) - 각각의 클라이언트가 접근할 수 있는 모든 파일 public
if(myId != null){
%>
<%=myId %>란 id를 가진 분이 선택한 드라마는<%=drama %> 입니다.<br>
세션 아이디: <%= session.getId() %><br>
세션 유효시간: <%= session.getMaxInactiveInterval() %>
<%
}else{
out.println("세션이 설정되지 않음");
}
%>
</body>
</html>
'Programming Language > Servlet & JSP' 카테고리의 다른 글
[JSP] Bean을 통한 값 전달 (0) | 2020.08.26 |
---|---|
[JSP] javaBeans *개념 미완성* (0) | 2020.08.26 |
[JSP] Redirect / Forward test 2 (feat. WEB-INF) (0) | 2020.08.26 |
[JSP] Redirect / Forward 방식 (0) | 2020.08.26 |
[JSP] 9개 내장객체 (0) | 2020.08.26 |
Comments