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
- #Git #Git Merge #깃 병합
- #JSP #Servlet #서블릿 #쿠키 #cookie #Cookie #쿠키클래스 #쿠키유틸클래스 #cookieClass #cookieUtilClass #Cookie #제이에스피
- #JSP #Servlet #제이에스피 #서블릿 #필터 #filter #web.xml #필터예제 #filter예제
- #JSP #Servlet #제이에스피 #서블릿 #필터 #Filter @WebFilter #어노테이션필터
- #게터 #세터
- #JAVA #정보은닉 #접근제어자 #private
- #JSP #Servlet #contextroot #contentdirectory
- JSP #Servlet #Exception #error #page #errorpage #exceptionPage #Customerror #톰캣 #404 #에러페이지 #java
- #.war #Export
- #JSP #Servlet #제이에스피 #서블릿 #세션 #session #세션로그인 #세션예제
- #Servlet #servletClass #servletURL #servlet구현 #JSP
- JAVA #JSP #Servlet #Exception #custom #익셉션 #에러처리 #에러
- #유틸클래스 #VO
- #JSP #Servlet #@WebServlet #urlPatterns
- #깃 #Git #Git cherry-pick #체리픽 #깃 체리픽
- JSP #Servlet #Exception #errorPage #web.xml #error-page #error-code #에러 #익셉션 #java
- #JSP #Servlet #Ajax #에이젝스 #HTML #success #.HTML() #HTML로붙이기
- #JSP #Servlet #Exception #errorPage #web.xml #error-page #error-code #에러 #익셉션 #java
- #JSP #Servlet #세션 #Session #제이에스피 #서블릿
- Git #Stash #깃 #스테시 #임시저장 #소스트리 #협업툴
- #JSP #Servlet #세션 #Session #제이에스피 #서블릿 #web.xml #세션알림 #알림팝업 #세션알림팝업 #session-timeout
- Listener #jsp #servlet #ServletContextListener #리스너
Archives
- Today
- Total
David의 블로그
[JSP/Servlet]상태를 유지할 수 있는 Session, 세션(세번째) 본문
이번에는
web.xml에 세션타임아웃을 등록하여 하나의 페이지에서 세션종료 알림 팝업 만들기를 해 볼 것이다.
서버에서 세션 시간을 정하는 방법은 두 가지가 있다.
1. session.setMaxInactiveInterval()
2. web.xml에 <session-timeout>를 통해 설정한다.
공통점은 세션 시간을 정하는 것이고, 차이점이라 하면
session.setMaxInactiveInterval()은 '초'로 설정해주고, <session-timeout>은 '분'으로 설정이 된다.
[web.xml에 세션타임아웃을 등록하여 하나의 페이지에서 세션종료 알림 팝업 만들기]
[web.xml]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>seesionPractice</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>1</session-timeout> <!-- 분으로 설정이 됨. -->
</session-config>
</web-app>
|
cs |
<sessio-config> 자식 태그로 <session-timeout>태그를 지정한다.
위에서 말한대로 해당 숫자는 '분'을 의미한다.
[aa.jsp]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<%@ 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>
<script type="text/javascript">
var secondsBeforeExpire = ${pageContext.session.maxInactiveInterval};
var timeToDecide = 45; // Give client 15 seconds to choose.
alert(secondsBeforeExpire)
setTimeout(function() {
alert('세션 타임아웃까지 ' + timeToDecide + ' 초 남았습니다~!~!~')
}, (secondsBeforeExpire - timeToDecide) * 1000);
</script>
</body>
</html>
|
cs |
11Line : web.xml에 등록한 세션 타임아웃 시간을 가져온다.
12Line : 세션 종료 알림 시간.
14 ~ 16Line : 서버에 등록된 세션 타임시간과 세션 종료 알림시간을 뺀 ?초 이후에 실행될 함수.
[결과]
'프로그래밍 > Jsp_Servlet' 카테고리의 다른 글
[JSP/Servlet]전처리 역할을 하는 Filter.필터 첫번째 (0) | 2024.01.28 |
---|---|
[JSP/Servlet] 서블릿과 Ajax로 통신 후에 결과를 HTML로 뿌려주기. (1) | 2024.01.21 |
[JSP/Servlet]상태를 유지할 수 있는 Session, 세션(두번째) (0) | 2024.01.20 |
[JSP/Servlet]상태를 유지할 수 있는 Session, 세션(첫번째) (0) | 2024.01.20 |
[JSP/Servlet]정보를 저장할 수 있는 객체 쿠키.Cookie (1) | 2024.01.06 |