gpt4 book ai didi

java - 素面 : submit after succes action

转载 作者:行者123 更新时间:2023-11-29 12:58:28 28 4
gpt4 key购买 nike

我创建了一个登录页面用户正确输入用户名和密码后,他将被引导到另一个页面(主页)

@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());
}
}
}

xhtml页面包含两个输入和命令按钮

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

它在控制台中向我显示欢迎,如果正确(通过/登录),否则错误

但如果密码和登录正确,我必须转到另一个页面

最佳答案

您可以像这样从 bean 更改当前页面:

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

对于显示消息,您可以使用:

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

并添加到您的 XHTML 页面中:

<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />

关于java - 素面 : submit after succes action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23689511/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com