| Author |
newbie : session problem
|
michael echavez
Greenhorn
Joined: Feb 07, 2005
Posts: 18
|
|
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
Joined: Aug 15, 2004
Posts: 2874
|
|
|
So, what are you getting as a count?
|
 |
Ashok Kumar
Ranch Hand
Joined: Aug 27, 2004
Posts: 93
|
|
|
Can you tell us what exactly do you see on the browser screen?Also do you see any errors in the TomCat Console?
|
"Decide what you want, decide what you are willing to exchange for it. Establish your priorities and go to work."
|
 |
Steve McCann
Ranch Hand
Joined: Oct 20, 2004
Posts: 81
|
|
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
Joined: Jan 10, 2002
Posts: 56162
|
|
|
Have you disabled cookies?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
michael echavez
Greenhorn
Joined: Feb 07, 2005
Posts: 18
|
|
|
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
Joined: Jan 10, 2002
Posts: 56162
|
|
|
No cookies generally means no session.
|
 |
michael echavez
Greenhorn
Joined: Feb 07, 2005
Posts: 18
|
|
|
no,i havent disabled cookies.
|
 |
michael echavez
Greenhorn
Joined: Feb 07, 2005
Posts: 18
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
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.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
michael echavez
Greenhorn
Joined: Feb 07, 2005
Posts: 18
|
|
|
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!
|
 |
 |
|
|
subject: newbie : session problem
|
|
|