Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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
Session 检索用户';只要会话在jsf中处于活动状态,就保留它_Session_Jsf - Fatal编程技术网

Session 检索用户';只要会话在jsf中处于活动状态,就保留它

Session 检索用户';只要会话在jsf中处于活动状态,就保留它,session,jsf,Session,Jsf,我在jsf中有一个web应用程序,我将在其中检索用户id,以便在其他managedbeans中重用。 每个用户都有一个会话,该会话在自动加密后立即创建,数据存储在Mysql数据库中。只要会话处于活动状态,我就会检索并保留用户存储的id。你能帮我吗 这是我的managedBean @ManagedBean @SessionScoped public class ProfManagedBeans { private int idp; private String email, pw

我在jsf中有一个web应用程序,我将在其中检索用户id,以便在其他managedbeans中重用。 每个用户都有一个会话,该会话在自动加密后立即创建,数据存储在Mysql数据库中。只要会话处于活动状态,我就会检索并保留用户存储的id。你能帮我吗

这是我的managedBean

@ManagedBean
@SessionScoped
public class ProfManagedBeans {

    private int idp;
    private String email, pwd;

    public HttpSession hs;

    public ProfManagedBeans() {
    }


    public int getIdp() {
        return idp;
    }

    public void setIdp(int id) {
        this.idp = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public static PreparedStatement pstmt=null;
    public static ResultSet rs = null;
    public String query="";
    public int dbid;
    public String dbemail, dbpwd;

    public String getDbemail() {
        return dbemail;
    }

    public String getDbpwd() {
        return dbpwd;
    }

    public void dbData(String uEmail){

        DbConnect.getConnection();
        query = "SELECT * FROM professeur where email='" + uEmail +"'";
        try {
            pstmt = DbConnect.conn.prepareStatement(query);
            ResultSet rs = pstmt.executeQuery();
            while(rs.next()){
                dbid = rs.getInt("id_pr");
                dbemail = rs.getString("email");
                dbpwd = rs.getString("pwd");
            }

        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("Exception " + e);
        }
    }

    public int getIdProf(){
        dbData(email);
        String ids = hs.getId();
        if(ids == hs.getId()){
            idp = dbid;
            return idp;
        }
        return 0;
    }

    public String login(){
        dbData(email);
        if (email.equals(dbemail)==true&&pwd.equals(dbpwd)==true) {
                hs = Util.getSession();
                hs.setAttribute("email", dbemail);
                System.out.println(hs.getId());
                System.out.println(getIdProf());
                return "success.xhtml"; 
            } 
            else {
                FacesMessage fm = new FacesMessage("Email error", "ERROR MSG");
                fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext.getCurrentInstance().addMessage(null, fm);
                return "LoginProf.xhtml";
            }
        }

        public String logout() {
            hs.invalidate();
            return "/LoginProf.xhtml";
        } 
}

public class QuestionManagedBeans {

    private int id,id_pr;

    private String nomDesc, question, type;
    private String reponse;
    private double noteV, noteF;
    private String niveau, matiere,chapitre, explication;

    public static PreparedStatement pstmt=null;
    public static ResultSet rs = null;
    public String query=""; 

    private ArrayList<Niveau> list ;

    public QuestionManagedBeans() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNomDesc() {
        return nomDesc;
    }

    public void setNomDesc(String nomDesc) {
        this.nomDesc = nomDesc;
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getReponse() {
        return reponse;
    }

    public void setReponse(String reponse) {
        this.reponse = reponse;
    }

    public double getNoteV() {
        return noteV;
    }

    public void setNoteV(double noteV) {
        this.noteV = noteV;
    }

    public double getNoteF() {
        return noteF;
    }

    public void setNoteF(double noteF) {
        this.noteF = noteF;
    }

    public String getNiveau() {
        return niveau;
    }

    public void setNiveau(String niveau) {
        this.niveau = niveau;
    }

    public String getMatiere() {
        return matiere;
    }

    public void setMatiere(String matiere) {
        this.matiere = matiere;
    }

    public String getExplication() {
        return explication;
    }

    public String getChapitre() {
        return chapitre;
    }

    public void setChapitre(String chapitre) {
        this.chapitre = chapitre;
    }

    public void setExplication(String explication) {
        this.explication = explication;
    }

    public int getId_pr() {
        return id_pr;
    }

    public void setId_pr() {
        ProfManagedBeans p = new ProfManagedBeans();
        this.id_pr = p.getIdProf();
    }

    public boolean insertQuestion() throws SQLException {

       Question q = new Question(id,nomDesc, question, type,reponse,noteV, noteF,niveau, matiere, chapitre ,explication,id_pr);
       setNomDesc("");
       setQuestion("");
       setType("");
       setReponse("");
       setNoteV(0.0);
       setNoteF(0.0);
       setNiveau("");
       setMatiere("");
       setChapitre("");
       setExplication("");
       return new InsertDao().insertQuestionTF(q);
    }
}

向我们展示代码并解释您的卡在哪里。@calexandre我修改了我的帖子添加代码并解释我的卡在哪里谢谢您的帮助实际问题是什么?会话范围的bean保存在内存中,您可以帮助我获取教授的id,并在验证后将其放入url中,然后在其他managedBean中获取此id吗
public boolean insertQuestionTF(Question qu) throws SQLException{

            DbConnect.getConnection();
            ProfManagedBeans p = new ProfManagedBeans();
            query ="INSERT INTO `question_tf` (`nomdesc`, `question`, `type`, `reponse`, `noteV`, `noteF`, `niveau`, `matiere`, `chapitre`, `explication`, `id_pr`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            pstmt = DbConnect.conn.prepareStatement(query);
            pstmt.setString(1, qu.getNomDesc());
            pstmt.setString(2, qu.getQuestion());
            pstmt.setString(3, qu.getType());
            pstmt.setString(4, qu.getReponse());
            pstmt.setDouble(5, qu.getNoteV());
            pstmt.setDouble(6, qu.getNoteF());
            pstmt.setString(7, qu.getNiveau());
            pstmt.setString(8, qu.getMatiere());
            pstmt.setString(9, qu.getChapitre());
            pstmt.setString(10, qu.getExplication());
            pstmt.setInt(11, p.getIdProf()); 

            System.out.println("insert " + p.getIdProf());

            if (pstmt == null) {
                throw new SQLException();
            } else {
                return pstmt.executeUpdate() > 0;
            }
        }