๋ฐ์ํ
โ
Counter.java
package scope;
public class Counter {
private int cnt = 0;
public int getCnt() {
this.cnt++;
return cnt;
}
public void setCnt(int cnt) {
this.cnt = cnt;
}
}
cntReset.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>
<jsp:setProperty property="cnt" name="testsession" value="0"/>
<script>
location.href="<%=request.getParameter("page")%>.jsp";
</script>
</body>
</html>
sessionScope.jsp (์คํ ํ์ด์ง)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์๋ฐ๋น session scope ํ
์คํธ</title>
</head>
<jsp:useBean id="testsession" class="scope.Counter" scope="session"/>
<body>
ํ์ฌ ๋ฐฉ๋ฌธ์ ์ :
<jsp:getProperty property="cnt" name="testsession"/>
<input type="button" value="์ด๊ธฐํ"
onclick="location.href='cntReset.jsp?page=sessionScope';">
</body>
</html>
<์คํ ๊ฒฐ๊ณผ>
๋ฐ์ํ
'JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JSP] ์ค์ต (Request scope๋ฅผ ์๋ฐ๋น์์ ์ฌ์ฉํ๊ธฐ) (0) | 2021.02.24 |
---|---|
[JSP] ์๋ฐ๋น์ ์ด์ฉํ ํ์ ๊ฐ์ ํผ ์์ฑ (0) | 2021.02.24 |
[JSP] JSP์์ ์๋ฐ๋น ์ฌ์ฉํ๊ธฐ (0) | 2021.02.24 |
[JSP] ์๋ฐ๋น (0) | 2021.02.24 |
[JSP] ์ก์ ํ๊ทธ๋ฅผ ํ์ฉํ ํ ํ๋ฆฟ ํ์ด์ง ์์ฑ (0) | 2021.02.10 |
๋๊ธ