Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSP
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
JSP
counter doesnt work
miguel lisboa
Ranch Hand
Posts: 1282
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i quote a Visualbuilder.com
jsp
tutorial:
Creating your second JSP page For the second example, we will make use of the different tags we have learnt. This example will declare two variables; one string used to stored the name of a website and an integer called counter that displays the number of times the page has been accessed. There is also a private method declared to increment the counter. The website name and counter value are displayed. <HTML> <HEAD> <TITLE> JSP Example 2</TITLE> </HEAD> <BODY> JSP Example 2 <BR> <%! String sitename = �visualbuilder.com�; int counter = 0; private void increment Counter() { counter ++; } %> Website of the day is <%= sitename %> <BR> page accessed <%= counter %> </BODY> </HTML>
if i run this example, counter allwy stays at zero!
i rewrote the code, adding, at the bottom:
<%= counter %> <%incrementCounter();%>
my Q: is this the correct way?
TiA
java amateur
Heonkoo Lee
Ranch Hand
Posts: 85
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Correct, but you might want to increment the counter before displaying it.
miguel lisboa
Ranch Hand
Posts: 1282
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
so that first visit shows 1 instead of 0, of course
thanks
java amateur
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Display of Latin Characters
Radio Button,Check Boxes
JSP declaration
pagination with tomahawks dataScroller
Java Bean Scope Attribute
More...