对不起我是新手,我正在尝试编写一个简单的表单登录,但是从我的xhtml表单中我在jsf控制器中获得了用户名和密码作为空参数...我使用了错误版本的jsf或者我做错了什么?
我的pom.xml:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.tomahawk</groupId>
<artifactId>tomahawk</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>net.bootsfaces</groupId>
<artifactId>bootsfaces</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
我的控制器类:在faces-config.xml中注册为控制器
@ManagedBean(name="controller")
@SessionScoped
public class Controller {
private String username;
private String password;
public String login() {
if (username.equals("user") && password.equals("password") ) return "second.xhtml";
FacesContext.getCurrentInstance().addMessage("error", new FacesMessage(
FacesMessage.SEVERITY_ERROR, "login succesful", null));;
return "login.xhtml";
}
// + getter and setter
这是我的表单:带有简单的错误消息......
<h:form id="error">
<div class="form-group">
<label for="exampleInputEmail1">User Name</label> <input
type="text" class="form-control" value="#{controller.username}"
placeholder="Enter User Name" required="required"></input>
</div>
<h:message for="error" errorStyle="color: red;" />
<div class="form-group">
<label for="exampleInputPassword1">Password</label> <input
type="password" class="form-control" value="#{controller.password}" placeholder="Password" required="required"></input>
</div>
<h:commandButton action="#{controller.login}" style="width: 100%; font-size: 1.1em;" value="Login" class="btn btn-large btn btn-success btn-lg btn-block">
</h:commandButton> </h:form>
请帮帮我:)。