public class : 사용자에 따라 계속바뀜.
session : 사용자 별도로 계속 유지됨
application : 계속바뀜.
******* src/MemberBean.java *******
package ch04;
public class MemberBean
{
public static String id;
public static String name;
}
*********** Ch0401.jsp ************
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
IP주소 : <%=request.getRemoteAddr() %>
getContextPath() : <%=request.getContextPath() %>
</body>
</html>
************* Ch0402.jsp *****************
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%><!--
Ch0402.jsp
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form action="Ch0402pro.jsp">
id : <input type="text" name="id"><p>
name : <input type="text" name="name"><p>
email : <input type="text" name="email"><p>
<input type="submit">
</form>
</body>
</html>
************* Ch0402pro.jsp ************
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%><!--
Ch0402pro.jsp
--><!--
src영역의 ch04패키지 참조
--><%@ page import="ch04.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("euc-kr");
/*
MemberBean.id=request.getParameter("id");
MemberBean.name=request.getParameter("name");
*/
session.setAttribute("id",request.getParameter("id"));
session.setAttribute("name",request.getParameter("name"));
//application.setAttribute("email",request.getParameter("email"));
//만약 처음으로 방문한 상태라면 appliction영역에는 count요소가 없다면.
if(application.getAttribute("count")==null)
{
application.setAttribute("counts",new Integer(1));
}
else
{
int count = (Integer)(application.getAttribute("counts"))+1;
application.setAttribute("count", new Integer(count));
}
%>
<script>
location="Ch0403.jsp";
</script>
</body>
</html>
************ Ch0403.jsp ***************
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%><!--
Ch0403.jsp
-->
<%@ page import="ch04.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<!-- 보이지는 않으나 구동은 됨.
di : <%= MemberBean.id %><p>
name : <%= MemberBean.name %><p>
-->
id : <%=session.getAttribute("id") %><p>
name : <%=session.getAttribute("name") %><p>
email : <%=application.getAttribute("email") %><p>
접속수 : <%=application.getAttribute("count") %>
<a href="Ch0404.jsp">소멸</a>
</body>
</html>
*************** Ch0404.jsp *****************
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<!--
JSP의 내장개체 영역 :
page 영역 :
request 영역 :
session 영역 :
application 영역 :
네가지다 추가시 setAttribute(), 제거시 removeAttribute(),
참조시 getAttribute()를 지원
-->
<%
session.removeAttribute("id");
session.removeAttribute("name");
%>
id : <%=session.getAttribute("id") %><p>
name : <%=session.getAttribute("name") %><p>
</body>
</html>