struts FormBean的用处

来源:互联网 发布:matlab2013a mac下载 编辑:程序博客网 时间:2024/05/17 02:35

自己从页面中各个控件中搜集数据,放入Form中,以供其他页面
使用(要把该Form的作用域设置为session)
public final class HelloForm extends ActionForm {

    private String userName = null;

    public String getUserName() {
        return (this.userName);
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
  
    /**
     * Reset all properties to their default values.
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        this.userName = null;
    }
}

 <action    path      = "/HelloWorld"
               type      = "hello.HelloAction"
               name      = "HelloForm"
               scope     = "session"
               validate  = "false"
               input     = "/view/test/hello.jsp"
     >
        <forward name="SayHello" path="/view/test/hello.jsp" />
    </action>

页面可以通过以下方式获得:
<bean:define id="helloForm" name="HelloForm" toScope="session"/>
      helloForm:<bean:write name="helloForm" /><br>
      helloForm.userName:<bean:write name="helloForm" property="userName"/>
    <br>
    <br>
    <logic:equal name="HelloForm" scope="session" property="userName" value="xiaoming">
     xiaoming is a good boy!
    </logic:equal>
    <br>
    <br>
    <logic:empty name="HelloForm" scope="session" property="userName">
        userName is empty!
    </logic:empty>

原创粉丝点击