Hello All, I have some doubt abt the declarations. I know that if we declare a variable like <% int x = 3 %>, then it will be in the service method, and local to it, and if we declare a variable as <%! int x = 3 %> then it will be in the class level, here the scope is upto the class, is it possible to access the same variable through out the application? what does class scope means here.
You can access that variable in jspInit and jspDestroy also. While former was accessible inside service method only.
Is it possible to access the same variable through out the application
Technically Yes! Since there is only one instance of a servlet so this variable will be one for whole application. But it would require a lot of extra stuff and also using context parameter is far better option.
Since you are in SCWCD forum.. I assume that you are SCJP
And a class level variable (non-static/instance variable) can be accessed by all the members of the class (So, in servlet, it can be accessed in init(), service(), doxxx(), destroy() and other user defined methods)
Hi arvind, U said, technically it is accessible throughout the appllication. so now my question is, if we declare another variable with the same name in another JSP, then how can we access the variables differently. Sri.