ot;false" contentType="text/html;charset=gb2312" %>
<jsp:useBean id="PseudoSessionId" scope="application" class="pseudosession.PseudoSessionBean" />
<% String sessionId = PseudoSessionId.getSessionID(request);%>
<html>
<head>
<title>伪会话</title>
</head>
<body>
<h1>伪会话管理机制</h1>
<% String userName = "bulbul"; PseudoSessionId.setValue(sessionId, "userName", userName);%>
<a href=secondPage.jsp?sessionId=<%=sessionId%>>点击此处</a>
<form method="post" action=anotherPage.jsp?sessionId=<%=sessionId%>>
输入数据:<input type="text" name="sample">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
<% PseudoSessionId.deleteAllInvalidSessions();%>
注意,包括<form>标记的action属性在内,所有的超级链接都已经改写,现在都包含了会话标识符。另外也请注意页面的最后调用了deleteAllInvalidSessions方法。
secondPage.jsp页面只简单地返回以前保存的用户名字。
<%@ contentType="text/html;charset=gb2312" page session="false" %>
<jsp:useBean id="PseudoSessionId" scope="application" class="pseudosession.PseudoSessionBean" />
<% String sessionId = PseudoSessionId.getSessionID(request);%>
<html>
<head>
<title>第2个页面</title>
</head>
<body>
<% String userName = PseudoSessionId.getValue(sessionId, "userName"); out.println("用户名字是 " + userName);%>
</body>
</html>