This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable doesn't increment

 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my web.xml


this is my jsp


i need to increment the value printed each time when i type this on broser
http://localhost:8080/test/
but it always gives 1.
why the count variable doesn't increment.
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you all the time declare it as zero?
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then what i have to change
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to declare count when each time the web browser hit it should increment the value.how should i declare it
?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you check this ? Tried refreshing the page?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the concept of the application context, and how you can use it to store values (called "attributes") throughout the application lifetime.
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes .i need to increment when refreshing?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anarkali perera wrote:yes .i need to increment when refreshing?

If you want this available to the whole appplication use javax.servlet.ServletContext or to a particular session use javax.servlet.http.HttpSession. The code you have given work only for that particulr jsp/URL.
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i change the web.xml

<context-param>
<param-name>var</param-name>
<param-value>1</param-value>
</context-param>

and i change the jsp

but it gives
The page var is now: null
why it gives null?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Context init parameters are not the same thing as context attributes. In particular, context init parameters are immutable, so you can't use them for what you want to do (except for fetching an initial value with which to seed the attribute).
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this very easily using a servlet :

declare a variable



then in servlet's doGet method write :




And in jsp, write,



 
Rituraj Jain
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buddy
may there is some other problem with your system but the value is increasing for me..i have copy pasted your program in my tomcat and while refreshing (internet explorer) the value is increasing as it should be.

and the variable declared in (Declaration Tag) <%! %> are same as to those which are declared at class level in case of servlets

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic