hi,
i need to know whether there is a way to change the value of a single variable by two servlet classes. in one servlet i need to make a variable =true and in another servlet i need to make the variable =false
hi,
i need to know whether there is a way to change the value of a single variable by two servlet classes. in one servlet i need to make a variable =true and in another servlet i need to make the variable =false
If you are want to store it you could use a HTTPSession and then any of the servlets will be able to access the variable.
HttpSession session = request.getSession();
session.setAttribute("hello", "test");
http://www.exforsys.com/tutorials/jsp/jsp-session-object-methods.html
Take a look at that page, some basic info on sessions.
What do you want exactly?
You can use singleton and keep that var there, or use session or request or whatever...
If you want a global variable for the entire web app, that is what attributes in the ServletContext are for - be sure to read the doc carefully so you understand how "global" these attributes are exactly.
If you want the variable to be individual per user, but global across servlets, that's what attributes in the HttpSession are for.
Stick the data in your database (or other persistent store).
There is the application context, but as Michael Borgwardt points out in his answer, that isn't actually global.