Java timeout login

1. Simple JS:

var myTime = setTimeout("Timeout()", 60000);

              Function resetTime() {
            
                  clearTimeout(myTime);
                  myTime = setTimeout('Timeout()',60000);
              }
                
              Function Timeout() {
                  Alert("Your login has timed out, please click OK and log in again!");
                  //window.location.href="/fudaMes/login.jsp";
                  //document.location.href="/fudaMes/login.jsp";
                  signOutMethod();
              }
                
              document.documentElement.onkeydown=resetTime;//When the trigger keyboard key time clears, re-clocking
                
              document.documentElement.onclick=resetTime;//When the page is clicked, the timer is reset to zero 

2. When the user logs in to the server, the server will assign a session to the user. If the user accesses the server with the same session, The server should be able to identify the user. After switching the web page, the server "does not know" the user. To do this, the background needs to create a map, bind a session to a user, and manage the online user by maintaining the map. Specific implementation look at the code:

public class ClientManager {  
      
    private static ClientManager instance = new ClientManager();  
      
    private ClientManager(){  
          
    }  
      
    public static ClientManager getInstance(){  
        return instance;  
    }  
      
    private Map<String,Client> map = new HashMap<String, Client>();  
      
    /** 
     *  
     * @param sessionId 
     * @param client 
     */  
    public void addClinet(String sessionId,Client client){  
        map.put(sessionId, client);  
    }  
    /** 
     * sessionId 
     */  
    public void removeClinet(String sessionId){  
        map.remove(sessionId);  
    }  
    /** 
     *  
     * @param sessionId 
     * @return 
     */  
    public Client getClient(String sessionId){  
        return map.get(sessionId);  
    }  
    /** 
     *  
     * @return 
     */  
    public Collection<Client> getAllClient(){  
        return map.values();  
    }  
  
}

2.1: Configuration: Configuring

 <session-config>
    <session-timeout>30</session-timeout>
  </session-config>

in webXML is to set the session expiration time to 30 minutes. Also need to remove the user login state when the session is destroyed, so you need to register the sessionListener:

2.2 plus listener: add configuration

  <listener>
    <listener-class>org.jeecgframework.web.system.listener.SessionListener</listener-class>
  </listener>

2.3 listener code in spring mvc:

public class SessionListener Implements HttpSessionListener {
Private Map<Integer, List<TSFunction>> shortcutFunctionMap = null;
Private SystemService systemService;
    Public SystemService getSystemService() {
Return systemService;
    }
@Autowired
Public void setSystemService(SystemService systemService) {
this.systemService = systemService;
}
    @Override
    Public void sessionCreated(HttpSessionEvent event) {
 
    }
    @Override
    Public void sessionDestroyed(HttpSessionEvent event) {
        / / When the session is destroyed
    HttpSession session = event.getSession();
// TSUser user = ClientManager.getInstance().getClient(session.getId()).getUser();
shortcutFunctionMap = null;

// systemService.addLog("user" + user.getUserName() + "quitped",
// Globals.Log_Type_EXIT, Globals.Log_Leavel_INFO);
ClientManager.getInstance().removeClinet(session.getId());
    }
 
}