Frage

I created a login page after the user enters the username and password correctly he is directed to another page (home page)

@ManagedBean
public class Superviseur {

    private String login; have get and set
    private String password;// have get and set
    public void checkLogin() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/supervision";
            Connection con = DriverManager.getConnection(url,"root", "");
            Statement stm = (Statement) con.createStatement();
            String rq = "select * from superviseur ";
            ResultSet res=stm.executeQuery(rq);
            while (res.next()) {
                Superviseur sup=new Superviseur();
                sup.setPassword(res.getString("password"));
                sup.setLogin(res.getString("login"));
                if(sup.getLogin().equals(login)&&sup.getPassword().equals(password)) {
                    System.out.println( "WELCOM");
                } else {
                    System.out.println("ERROR login/password ");
                }
        } catch (Exception e) {
            System.out.println("ERROR :" + e.getMessage());
        }
    }
}

the xhtml page contains two input and the commande button

<p:commandButton  value="login" action="#{superviseurBean.checkLogin()}" />

it displays to me in the console welcome if right (pass/login) else ERROR

but i have to go to another page if the password and login are right

War es hilfreich?

Lösung

You could change your current page from bean like this :

FacesContext.getCurrentInstance().getExternalContext().redirect("/accueil.jsf");

And for show message you can use :

 FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,"Sample warn message", "Watch out for PrimeFaces!"));

And add in your XHTML page :

<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top