This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
hi friends i want to use a variable which is static like we use in java. i mean if j=0 at begining and if j++ then it will be j=1 like wise value of j will keep increasing should not assign j=0 again. i know in java i write public static int j=0;
If you REALLY want to declare a static variable in a JSP, you just need to use the declaration syntax.
<%! static int myStatic = 0 %>
However, as already mentioned, it is not really recommended to use java code in a JSP.
If what you want is a hit counter, you might consider implementing a filter that intercepts all requests, and examines the request url to keep track.
The nice thing about that approach is that all of your counting code is just in that filter, and not polluting your JSP pages.
Bear in mind that using any Java in a JSP page is obsolete and considered a very poor practice. Also bear in mind that introducing declarations in a JSP is a great way to introduce thread-safety problems.
There are many good reasons that Java scriptlets have been discredited and obsolete for over 11 years!