我正在尝试创建一个登录页面,用于检查数据库中的用户名和密码。当我单击提交按钮时,它会显示welcome.xhtml 文件的代码,而不是显示欢迎页面。谁能告诉我如何解决这个问题。
在更改 login.xhtml 以使用 facelets 后,我仍然遇到同样的问题。
登录.xhtml:
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<h:form>
<p>
<h:inputText
id="username"
title="Username"
value="#{userBean.username}">
<h:inputText
id="password"
title="Password"
value="#{userBean.password}">
</h:inputText>
<h:commandButton id="submit" value="Submit" action="#{userBean.validate}"/>
</p>
</h:form>
</h:body>
托管豆:
@Stateless
public class userBean implements Serializable {
private String username, password;
private String response = "";
private UserFacade userFacade;
public userBean() {
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return username;
}
public void setUserName(String username) {
this.username = username;
}
public String validate(){
System.out.println("in bean");
response = userFacade.validateUser(username, password);
if (response.equals("MATCH"))
return "welcome.xhtml";
else
return "login.xhtml";
}
}