on
1021_JSP/Servlet : 세션 Session
1021_JSP/Servlet : 세션 Session
sessionEx2
<%@ page contentType="text/html; charset=UTF-8"%> <%@ page trimDirectiveWhitespaces="true"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> Insert title here session : 클라이언트의 정보를 서버에 저장 세션 설정 | 세션 확인 | 세션 제거
sessionSet
<%@ page contentType="text/html; charset=UTF-8"%> <%@ page trimDirectiveWhitespaces="true"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <% // session : 세션을 나타내는 JSP 내장 객체(HttpSession) // 서블릿에서 세션 객체 구하기 : HttpSession sess = request.getSession(); // EL에서의 세션 객체 : sessionScope // 세션 유지시간 설정(톰캣 기본 세션 유지시간 : 30분) session.setMaxInactiveInterval(60*20); // 단위 : 초 session.setAttribute("name", "홍자바"); session.setAttribute("age", 20); %> Insert title here session 설정 돌아가기
sessionInfo
<%@page import="java.util.Date"%> <%@page import="java.text.SimpleDateFormat"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ page trimDirectiveWhitespaces="true"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <% String name = ""; int age = 0; try { // 세션에 설정한 값 가져오기 name = (String)session.getAttribute("name"); age = (Integer)session.getAttribute("age"); } catch(Exception e) { } // 세션 유지시간 int interval = session.getMaxInactiveInterval(); // 세션 아이디 String id = session.getId(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // 세션 생성 시간 Date date1 = new Date(session.getCreationTime()); String create_date = sdf.format(date1); // 세션 마지막 접속 시간 Date date2 = new Date(session.getLastAccessedTime()); String last_date = sdf.format(date2); %> Insert title here session 정보 이름과 나이 : <%=name%>, <%=age%> EL을 이용하여 세션 값 가져오기 : ${sessionScope.name}, ${sessionScope.age} 세션 최대 유지시간 : <%=interval / 60 %>분 세션 아이디 : <%=id%> 세션 생성 시간 : <%=create_date %> 세션 마지막 접속 시간 : <%=last_date %> 돌아가기
sessionRemove
from http://development-writing.tistory.com/334 by ccl(S) rewrite - 2021-10-25 07:02:11