Back-end/JSP

[JavaSpring] session

peridott 2024. 7. 16. 15:47
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>session</h1>
	<form action="05.2.session.jsp">
		ID : <input name="id"><p/>
		PW : <input type="password" name="pwd"><p/>
		<input type="submit">
		<input type="reset">
	</form>
</body>
</html>
<%@ 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>
	<%
		String id = request.getParameter("id");
		String pw = request.getParameter("pwd");
		
		session.setAttribute("idKey", id);
		session.setMaxInactiveInterval(60);
	%>
	<h1>Session Ex</h1>
	<form method="post" action="05.3.session.jsp">
		1. 가장 좋아하는 계절은?<p/>
		<input type="radio" name="season" value="봄">봄&emsp;
		<input type="radio" name="season" value="여름">여름&emsp;
		<input type="radio" name="season" value="가을">가을&emsp;
		<input type="radio" name="season" value="겨울">겨울<p/>
		
		2. 가장 좋아하는 과일은?<p/>
		<input type="radio" name="fruit" value="사과">사과&emsp;
		<input type="radio" name="fruit" value="포도">포도&emsp;
		<input type="radio" name="fruit" value="딸기">딸기&emsp;
		<input type="radio" name="fruit" value="자두">자두<p/>
		
		<input type="submit">
	</form>
</body>
</html>
<%@ 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>
<%
	String season = request.getParameter("season");
	String fruit = request.getParameter("fruit");
	
	String id = (String)session.getAttribute("idKey");
	String sessionId = session.getId();
	int intervalTime = session.getMaxInactiveInterval();
%>
</head>
<body>
<%
	if(id != null) {
%>
		<h1>Session Ex1</h1>
		<%=id %>님이 좋아하는 계절과 과일은 <%=season %>과 <%=fruit %>입니다<p/>
		세션 ID : <%=sessionId %><p/>
		세션 유지시간 : <%=intervalTime %>초<p/>
<%
		session.invalidate();
	} else {
		out.print("세션의 시간이 경과하였거나 다른 이유로 연결 할 수 없습니다");
	}
%>
</body>
</html>

'Back-end > JSP' 카테고리의 다른 글

[JavaSpring] pageContext  (2) 2024.07.16
[JavaSpring] application  (0) 2024.07.16
[JavaSpring] out  (0) 2024.07.16
[JavaSpring] request_infoMethod  (0) 2024.07.16
[JavaSpring] request  (0) 2024.07.16