• 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

newbie : session problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, what are you getting as a count?
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you disabled cookies?
 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No cookies generally means no session.
 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no,i havent disabled cookies.
 
michael echavez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic