GWT session management

2020-07-13 06:37发布

I don't too much about gwt session on java. I've some doubts about it. Anyone can check if the implementation below is the way it needs to be done.

public class ServiceImpl extends RemoteServiceServlet implements Service  
{
   void CreateSession(String Username)
   {
      HttpServletRequest request = this.getThreadLocalRequest();
      HttpSession session = request.getSession();
      session.setAttribute("Username", Username);
   }

   boolean ValidateSession(String Username)
   {
       HttpServletRequest request = this.getThreadLocalRequest();
       HttpSession session = request.getSession();
       if (session.getAttribute("Username"))
       {
          return true;
       }
       return false;
   }
}

Is this the correct way to implement these two function???

2条回答
Evening l夕情丶
2楼-- · 2020-07-13 07:08

This LoginSecurityFAQ is a good place to start.

查看更多
倾城 Initia
3楼-- · 2020-07-13 07:10

a few correction

    void createSession(String Username) {
        getThreadLocalRequest().getSession().setAttribute("Username", Username);
    }

    boolean validateSession(String Username) {
        if (getThreadLocalRequest().getSession().getAttribute("Username") != null) {
            return true;
        } else {
            return false;
        }
    }
查看更多
登录 后发表回答