this is the code I have in my index.java
public class index{
static final String DATABASE_URL = "jdbc:mysql://localhost:3306/try?zeroDateTimeBehavior=convertToNull";
Connection con;
Statement stmt;
ResultSet rs;
PreparedStatement pstmt;
private String id;
private String password;
private String message;
private String action;
public String getId() {return id;}
public void setId(String id) {this.id = id;}
public String getMessage() {return message;}
public String getPassword() {return password;}
public void setPassword(String password) {this.password = password;}
public String login(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/try?user=root&password=123");
String sql = "Select * FROM personnel WHERE pID =? AND password = ?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, id);
pstmt.setString(2,password);
rs=pstmt.executeQuery();
if(rs.next()){
action = "table";
}
else{action = null;
message="wrong password";}
}
catch(Exception e){}
return action;
}
}
public String modify(){
return "modify";}}
I built 3 pages first one for login:
<h:head>
<title>Log in</title>
</h:head>
<h:body>
<h:form>
<h:outputText id="output" value="#{index.message}"/>
<br/>
IDnumber: <h:inputText id="personnelID" value ="#{index.id}"/>
<br/>
Password: <h:inputSecret id="password" value ="#{index.password}"/><h:commandButton value="submit" action="#{index.login()}"/>
</h:form>
</h:body>
second for display a table:
<h:head>
<title>table</title>
</h:head>
<h:body>
<h:form>
My Tasks:
ID =<h:outputText id="output" value="#{index.id}"/>
<h:commandButton value="Modify My Task" action="#{index.modify()}"/>
</h:form>
</h:body>
third for modify:
<h:head>
<title>Modify</title>
</h:head>
<h:body>
<h:form>
ID =<h:outputText id="output" value="#{index.id}"/>
</h:form>
</h:body>
My problem is, the table page can still display the id i used to log in, but the third page just return id as null. What am I doing wrong??