所有请求参数都在#{param}
地图可用的 EL 中。因此,这应该这样做:
<p>Username: #{param.txtUsername}</p>
<p>Password: #{param.txtPassword}</p>
如果需要通过 Java 代码对它们进行预处理,最好将它们作为托管属性或视图参数放在与login.xhtml
.
托管属性示例:
@ManagedBean
@RequestScoped
public class Login {
@ManagedProperty("#{param.txtUsername}")
private String username;
@ManagedProperty("#{param.txtPassword}")
private String password;
@PostConstruct
public void init() {
// Do here your thing with those parameters.
System.out.println(username + ", " + password);
}
// ...
}
查看参数示例:
<f:metadata>
<f:viewParam name="txtUsername" value="#{login.username}" required="true" />
<f:viewParam name="txtPassword" value="#{login.password}" required="true" />
<f:event type="preRenderView" listener="#{login.init}" />
</f:metadata>
和
@ManagedBean
@RequestScoped
public class Login {
private String username;
private String password;
public void init() {
// Do here your thing with those parameters.
System.out.println(username + ", " + password);
}
// ...
}
也可以看看: