Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Web-如何使会话不停止?_Java_Web_Java Ee 7 - Fatal编程技术网

Java Web-如何使会话不停止?

Java Web-如何使会话不停止?,java,web,java-ee-7,Java,Web,Java Ee 7,我的问题是,我登录到运行正常的Java Web应用程序,在登录到另一个网站后,“jsessionid”消失,我必须再次登录。如何保持登录状态 @ManagedBean public class SecurityBean { private boolean loggedIn = false; private String username; private String password; private String template; public S

我的问题是,我登录到运行正常的Java Web应用程序,在登录到另一个网站后,“jsessionid”消失,我必须再次登录。如何保持登录状态

@ManagedBean
public class SecurityBean {
    private boolean loggedIn = false;
    private String username;
    private String password;
    private String template;

    public String getUsername(){
        return username;
    }

    public void setUsername(String username){
        this.username = username;
    }

    public String getPassword(){
        return password;
    }

    public void setPassword(String password){
        this.password = password;
    }
    public boolean isLoggedIn(){
        return loggedIn;
    }
    public void setLoggedIn(boolean loggedIn){
        this.loggedIn = loggedIn;
    }
    public String getTemplate(){
        if(loggedIn){
            return "/WEB-INF/templates/user.xhtml";
        }else{
            return "/WEB-INF/templates/main.xhtml";
        }
    }
    public void setTemplate(String template){
        this.template = template;
    }

    public String login(){
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        try{
            request.login(username, password);
        }catch(ServletException e){
            context.addMessage(null, new FacesMessage("Login failed"));
            return "error";
        }
        loggedIn = true;
        return "user/home"
    }

    public void logout(){
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        try{
            request.logout();
            loggedIn = false;
        }catch(ServletException e){
            context.addMessage(null, new FacesMessage("Logout failed"));
        }
    }

}

将您需要的任何信息保存在cookie中。它已经是:(您使用的是什么应用程序服务器?您使用什么登录到应用程序?