I have an application where Servlet has a method called Update(ReqIn, ReqOut)
. I call it from doGet
& doPost
and pass the Request and Response variables, and it is then up to Update(...)
to fill out the following static variables:
...
public class Server extends HttpServlet {
public static HttpServletRequest In = null;
public static HttpServletResponse Out = null;
public static boolean isDebug = true;
public static boolean isPost = false;
public static String URL = "";
public static String IP = "0.0.0.0";
public static Cookie[] Cookies = null;
public static UserClass User = null;
public static boolean isLoggedIn = false;
...
}
Basically Abstracting most used stuff & updating it on every request. This also allows me to access IP address & current user data from anywhere in the website, by writting just Server.User.getUsername();
insead of making a new Class instance everytime a page is loaded and using much longer access code: Server.getUser().getUsername();
Now the question is: When in multi user environment (Jetty on AppEngine), can this introduce any problems? E.g. some threading/racing issues making user see incorrect IP address or in extreme case suddenly being logged in as different user?
Or should I rewrite code and change it to Public UserClass User
instead of Public static UserClass User
, etc?