When login page is loaded the input text box is displaying #{ad.userid}
. When I erased it and entered id and pwd and clicked submit button the login method is called but userid property is giving null value in bean. How can this happen and how can I solve it?
Here is the login.jsp
:
<%@ page contentType="text/html"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<html>
<h:form>
<h:outputText value="Login"/>
<h:inputText value="#{ad.userid}" id="log" required="true"/>
<h:outputText value="Password" />
<h:inputSecret id="pw" value="#{ad.password}" required="true"/>
<h:commandButton value="submit" action="#{ad.login}"/>
</h:form>
</body>
</html>
</f:view>
Here is the bean's action method. The login worked successfully earlier. All db connections are set in constructor.
public String login() {
ResultSet rs;
try {
System.out.println(userid); // this is giving null
String s = "select id from slogin where id='" + userid + "'";
System.out.println(s);
rs = st.executeQuery(s);
if (rs.next()) {
String loginid = rs.getString(1);
if (userid.equals(loginid)) {
id = loginid;
return "studhome";
}
} else {
System.out.println("error");
}
} catch(Exception e) {
}
}
Getter and setter methods:
public void setpassword(String pass) {
this.password = pass;
}
public String getpassword() {
return password;
}
public void setuserid(String uid) {
this.userid = uid;
}
public String getuserid() {
return userid;
}