我正在构建一个小型扑克应用程序来提高我的 java 技能。我正在以德州扑克格式创建它。
基本上我想在处理我的 AJAX 响应的 servlet 中保持手状态。我猜 servlet 中的成员变量是不安全的,而会话应该是。你能解释一下这个解决方案的正确实现吗?
public class PokerClientResponse extends HttpServlet {
private static Logger LOG = Logger.getLogger(PokerClientResponse.class);
private static final long serialVersionUID = 1L;
private HandState handState = null;
public PokerClientResponse() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//Which is the best way to maintain hand state?
//Get the State from the session, then increment it
HttpSession session = request.getSession();
Object obj = session.getAttribute("handState");
//Advance the Hand State
getHandState().goToNextState();