charlotte49er
Programmer
Okay, I am a newbie here so be gentle...What I want to do is have a hit counter that uses a session variable so that the hit counter is increased only if the visitor hasn't been around for awhile. My code below works fine as long as I comment out the code line relating the session. However, when I try to implement the conditional based on the session, it craps out on me. Can someone give any suggestions as to why this won't work or maybe some sample code? Thanks.
Code:
<%@page contentType="text/html"%>
<%@page import = "java.util.*" %>
<%@page import = "java.io.*" %>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
Integer accessCount = (Integer)session.getAttribute("accessCount");
if (accessCount == null) {
// Create a File OutputStream
FileOutputStream fos = new FileOutputStream("test.dat");
// Create a DataOutputStream and chain it to the FileOutputStream
DataOutputStream dos = new DataOutputStream(fos);
// Write values to the file
dos.writeDouble(Math.sqrt(50));
// Close the output stream
dos.close();
fos.close();
// Create a FileInputStream
FileInputStream fis = new FileInputStream("test.dat");
// Create DataInputStream which is chained to the FileInputStream
DataInputStream dis = new DataInputStream(fis);
// Read the values
out.println(dis.readDouble());
// Close the input streams
dis.close();
fis.close();
}
session.setAttribute("accessCount", accessCount);
%>
</body>
</html>