我有以下html文件:
<h:body>
<h:form id="loginForm">
<p:growl id="msg" showDetail="true" life="3000" />
<p:panel header="Login" style="width: 360px;">
<h:panelGrid id="loginPanel" columns="2">
<h:outputText value="Username" />
<p:inputText id="username" value="#{loginBean.uname}" ></p:inputText>
<p:spacer></p:spacer>
<p:message for="username" ></p:message>
<h:outputText value="Password" />
<p:password id="password" value="#{loginBean.password}" feedback="false"></p:password>
<p:spacer></p:spacer>
<p:message for="password"></p:message>
<p:spacer></p:spacer>
<p:commandButton action="#{loginBean.loginPro}" value="Login" update="loginForm" ajax="true"></p:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
LoginBean如下:
@ManagedBean(name = "loginBean")
@SessionScoped
public class LoginBean implements Serializable {
private static final long serialVersionUID = 1L;
private String uname;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String loginPro() {
boolean result = false;
try {
result = UserDAO.login(uname, password);
} catch (SQLException e) {
e.printStackTrace();
}
if (result) {
return "home";
} else {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
"Invalid Login!",
"Please Try Again!"));
return "login";
}
}
当LoginBean上存在loginPro方法时,我继续收到以下消息:
javax.servlet.ServletException:/index.xhtml:Property&#39; loginPro&#39;在类型beans.LoginBean上找不到 javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
有什么意见吗?
答案 0 :(得分:0)
尝试loginBean.loginPro()
使用loginBean.loginPro你说有一个带有get / set
的属性变量答案 1 :(得分:0)
我遇到了同样的问题,并解决了在开头添加下面的代码段
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">