• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why not session.setAttribute working ?

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to display count of page hit through session but every time its displaying s1=0,either its not setting the attribute of session or what?
The code is given below :
<%@ page import = "java.io.*,
java.util.*,
java.sql.*"
session="true"
%>
<%! int a; %>
<%
Integer s1 = (Integer)session.getAttribute("sess");
out.println("s1 before " + s1);
if (s1==null) {
s1 = new Integer(0);
}
else {
s1 = new Integer(s1.intValue()+1);
}
session.setAttribute("sess",s1);
out.println("s1 after " +s1);

%>
<html>
<body> No of times you request for the page !</body></html>
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is displaying what you want. This is how your code output looks like.
s1 before null s1 after 0 No of times you request for the page !
s1 before 1 s1 after 2 No of times you request for the page !
s1 before 2 s1 after 3 No of times you request for the page !
s1 before 3 s1 after 4 No of times you request for the page !
------- ,,-----------
If you keep hitting refresh button, it's changing its value.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I ran your JSP on Tomcat 3.2 and it's working fine, just as Mandy described.
-anthony
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic