Can you suggest a wayout of how I can declare a Global variable in JSP which can be accessed by various methods, like we do in init() method of Servlets ?
i dont know which specification of jsp u r using but in jsp 1.1 spec there is a method called jspinit() which i think may be useful for u.
You can place objects in the application object. All JSPs have access to this scope, so it would indeed be global.
I understand what you are trying to do. But Java doesn't have the concept of global variable. Instead you can declare class members or instance members, either they are member methods or variables.
To do this in JSP, you just need to use the declarative tag
<% [varviable or function declaration] %>
<% private int id; %> declares a private integer named id;
<% public static int id; %> declares a public integer id with class scope.
You can also put methods inside the tag.
OOPS, I meant <%! ... %> rather than <% ... %>. Sorry that my finger moved too fast.
<%! [varviable or method declaration] %>
<%! private int id; %><%! public static int id; %>
u can write a bean and store ur global variable there...