Hi guys, This is really interesting,don't declare global variables in Servlet or Action Servlet.If you declare Name as a global variable , if user 'A' log's in and set his Name in the variable ,in the mean time if user 'B' log's in and set his name in variable,then user 'A' will have same value in global variable as that of 'B'.Reason,Container always creates a new thread for every request,this thread only execute service method,so the global variables are global for all the user..So avoid using global variables in Servlet... If i m not right please correct me...according to my observation i faced this problem in my application and overcome by removing global variable.
When user log's in to our system we used to save his information like first name last name etc.we used global variable for that,since we are using that variables across different function,Now suppose user 'A' logs in his information will be saved in this variables,im mean time if user 'B' logs in his information will be over ridden so ,user who logged in first will loose his information,and his name will change to that of 'B'
They are NOT global variables but instance variables. As they are available to any thread and for every request there is a new thread, the chances are high to have an ambiguity on the variable's value.
Instead you can have a local variable in either of doGet() or doPost() method which are definitely threadsafe since every thread will get its own copy.