• Post Reply Bookmark Topic Watch Topic
  • New Topic

newbie : session problem  RSS feed

 
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.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what are you getting as a count?
 
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?
 
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 ]
 
Author and ninkuma
Marshal
Posts: 66541
160
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
Posts: 66541
160
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 ]
 
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!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!