首页 > 解决方案 > 当我连接到工作台时,jsf 设置错误

问题描述

我是 java ee 的新手,我正在尝试使用 java ee 创建我的第一个网站,但是当我想将我的 jsf 连接到工作台时我发现很多困难我也有序列化问题,因为我总是生成手动 bean 序列

这是我的豆子 Userbean.java

@ManagedBean
@Named /*("userBean")*/ 
@RequestScoped
public class Userbean implements Serializable{

private static final long serialVersionUID = 1043069413653729199L;

private String iduser="";
private String username="name";
private String password="0000";
private String email="";
private String city="";
private String country="";

public Userbean() {
    super();
    // TODO Auto-generated constructor stub
}

public Userbean(String iduser, String username, String password, String email, String city, String country) {
    super();
    this.iduser = iduser;
    this.username = username;
    this.password = password;
    this.email = email;
    this.city = city;
    this.country = country;
}

public String getIduser() {
    return iduser;
}

public void setIduser(String iduser) {
    this.iduser = iduser;
}

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 String getEmail() {
    return email;
}

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

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}
public String returnAction2() {
    PreparedStatement ps;
    String query ="INSERT INTO `jee`.`user`( `username`, `email`, `password`, `city`, `country`) VALUES (?,?,?,?,?)";
    boolean a=false;
    try {
        ps= Myconnection.getConnection().prepareStatement(query);

        ps.setString(1,username);
        ps.setString(2,email);
        ps.setString(3,password);
        ps.setString(4,city);
        ps.setString(5,country);


        if(ps.executeUpdate()>0){
        a=true;
        }
    } catch (SQLException ex) {
        ex.getStackTrace();
        a=false;
    }

    return a==true ? "success" : "failure";
}

}

这是我的观点注册

<!DOCTYPE html>
<html xmlns:f="http://xmlns.jcp.org/jsf/core" 
  xmlns:h="http://xmlns.jcp.org/jsf/html">
<f:view>
    <head>
        <title>Login screen</title>
        <link rel="stylesheet" type="text/css" href="styles.css" />
    </head>
    <body>
        <h1>sign up</h1>

        <h:form>

            username: 
            <h:inputText id="username" value="#{userBean.username}" />
            <br/>

            Password:
            <h:inputSecret id="password1" value="#{userBean.password}" />
            <br/>
             email:
            <h:inputSecret id="email" value="#{userBean.email}" />
            <br/>
             city:
            <h:inputSecret id="city" value="#{userBean.city}" />
            <br/>
             country:
            <h:inputSecret id="country" value="#{userBean.country}" />
            <br/>



            <h:commandButton action="#{userBean.returnAction2}" value="Connect" />

       </h:form>
    </body>
</f:view>
</html>

标签: jsfjakarta-eemysql-workbenchjavabeanseclipse-jee

解决方案


推荐阅读