I am exploring session object in
servlets. when I am using session's getAttribute() I get compile time error. Kindly let me know what's wrong in this code..
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionTracker extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out=res.getWriter();
HttpSession session=req.getSession(true);
Integer count=(Integer)session.getAttribute("count");
if(count==null) {
count=new Integer(1);
}
else{
count=new Integer(count.intValue() +1);
}
session.setAttribute("count", count);
out.println("<html><head><title>Session Details</title></head>");
out.println("<body>You have visited this page" +count+((count.intValue()==1)? " time." : "times.") +"<br/>");
out.println(session.getId());
out.println(session.isNew());
out.println(new Date(session.getLastAccessedTime()));
out.println("</body></html>");
}
}