sesscount.jsp: Count Session Access
<%@ page import="java.util.Enumeration" %>
<%!
private static final String textname = "text";
private static final String countname = "counter";
%>
<%
Integer count = (Integer) session.getAttribute (countname);
if (count == null)
count = new Integer (0);
String text = request.getParameter (textname);
if (text == null)
text = (String) session.getAttribute (textname);
else
{
session.setAttribute (textname, text);
count = new Integer (count.intValue () + 1);
session.setAttribute (countname, count);
}
String url = response.encodeURL (request.getRequestURI ());
%>
<html>
<head>
<title>JSP Session Counter</title>
</head>
<body>
<h1>JSP Session Counter</h1>
Session = <code><%= session.getId () %></code>
<p>
<form method=post action=<%= url %> >
<input type=text name=<%= textname %>
<%
if (text != null)
{
%>
value="<%= text %>"
<%
}
%>
>
<input type=submit name=submit value="Save Text">
</form>
<p>
Count = <code><%= count %></code>
<p>
<a href=<%= url %> >Nochmal</a>
</body>
</html>