通过JSF Managed Bean捕获Post参数

时间:2018-06-06 20:58:41

标签: jsf post

C#windows应用程序将发布请求发送到JSF应用程序。有没有什么办法可以捕获发送给托管bean捕获的值?我累了this例子,但失败了。

这适用于获取请求,但不适用于帖子请求。

JSF文件

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core">
    <f:metadata>
        <f:viewParam name="username" value="#{bean.username}"  />
        <f:viewParam name="password" value="#{bean.password}" />
        <f:viewParam name="msg" value="#{bean.msg}" />
        <f:viewAction action="#{bean.init}" />
    </f:metadata>
    <h:head>
        <title>Response</title>
    </h:head>
    <h:body>

    #{bean.username}
    #{bean.password}
    #{bean.msg}


    </h:body>
</html>

JSF Managed Bean

/ *  *要更改此许可证标题,请在“项目属性”中选择“许可证标题”。  *要更改此模板文件,请选择“工具”|模板  *并在编辑器中打开模板。  * / 包bean;

import java.io.Serializable; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.context.FacesContext;

/ **  *  * @author buddh  * / @ManagedBean @ViewScoped 公共类Bean实现Serializable {

//属性-------------------------------------------- -------------------------------------

private String username;
private String password;
private String msg;

// Services -----------------------------------------------------------------------------------



// Actions ------------------------------------------------------------------------------------

public void init() {
    System.out.println("username = " + username);
    System.out.println("password = " + password);
    System.out.println("msg = " + msg);
   if(username==null||password==null||msg==null){
       FacesContext.getCurrentInstance().addMessage(null, 
            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please submit all data?", null));
        return;
   } 

}

// Getters/setters ----------------------------------------------------------------------------





public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getMsg() {
    return msg;
}

public void setMsg(String msg) {
    this.msg = msg;
}

}

0 个答案:

没有答案