Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

newbie : session problem

 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone! I'm a newbie with JSP and I've tried a jsp example from the book "Mastering Jakarta Struts." I typed the code exactly as written in the book but i can't seem to make it work. Everytime i press the refresh button the count does not increment - which is what it is supposed to do. Below is the code for the jsp:

<html>
<head>
<title>Session Example</title>
</head>
<body>
<%
Integer count = (Integer)session.getAttribute("COUNT");
if(count==null) {
count=new Integer(1);
session.setAttribute("COUNT", new Integer(1));
}
else {
count=new Integer(count.intValue() + 1);
session.setAttribute("COUNT", count);
}
out.println("<b>You have accessed this page: " + count + " times</b>");
%>
</body>
</html>

I'm using tomcat 5.5 by the way. I hope someone can help me out with this. Thank you.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what are you getting as a count?
 
Ashok Kumar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us what exactly do you see on the browser screen?Also do you see any errors in the TomCat Console?
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code works for me!
I pasted it into a JSP, refreshed the page and the counter incremented fine.

No problem.

Steve
[ June 10, 2005: Message edited by: Steve McCann ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you disabled cookies?
 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the count does not increment even as i refresh the page. would the problem be in my browser settings (like cookie control)?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No cookies generally means no session.
 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no,i havent disabled cookies.
 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even as the count doesnt increment, whenever i check tomcat manager, the number of sessions add up. it seems that everytime i click on refresh a new session is made and thus the count still remains at 1.
[ June 12, 2005: Message edited by: michael echavez ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a separate section for session cookies in MSIE.
It's under the privacy -> advanced tab.
There is a checkbox with the label "Always Allow Sessoin Cookies".

See if that is checked.
Also, download and install FireFox. It's never a bad Idea to have a couple browsers to use for testing your app.
 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i love mozilla firefox. that's what im using and ive also tried it on msie. i finally figured out what the problem was and it was a bit connected to cookie control - it was my firewall. i tried shutting down my firewall for a while just to see if it had anything to do with the problem, and as it turns out - it was the problem. In any case, i would like to thank all those people who posted their replies to my message - all of you guys gave me hints on how jsps actually work! Thank you so much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic