File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes variable doesn't increment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "variable doesn Watch "variable doesn New topic
Author

variable doesn't increment

anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
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

Joined: Aug 18, 2009
Posts: 174

Because you all the time declare it as zero?
anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
then what i have to change
anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
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

Joined: Mar 24, 2008
Posts: 3775

How did you check this ? Tried refreshing the page?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39542
    
  27
Check out the concept of the application context, and how you can use it to store values (called "attributes") throughout the application lifetime.


Ping & DNS - updated with new look and Ping home screen widget
anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
yes .i need to increment when refreshing?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

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

Joined: Sep 10, 2009
Posts: 237
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
Marshal

Joined: Mar 22, 2005
Posts: 39542
    
  27
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

Joined: Mar 28, 2007
Posts: 403
You can do this very easily using a servlet :

declare a variable



then in servlet's doGet method write :




And in jsp, write,




Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Rituraj Jain
Ranch Hand

Joined: Nov 28, 2008
Posts: 37
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


Rituraj Jain
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variable doesn't increment
 
Similar Threads
Deployement problem
EL Configuration Problem
runtime ERROR
Unable to find taglib in project--please help
can't find file tad lib descriptor:"http://java.sun.com/jstl/core"