解决方案 »

  1.   

    Struts 2 does not have "forms" like Struts 1 did. In Struts 2 request parameters are bound directly to fields in the actions class, and this class is placed on top of the stack when the action is executed.If an action class implements the interface com.opensymphony.xwork2.ModelDriven then it needs to return an object from the getModel() method. Struts will then populate the fields of this object with the request parameters, and this object will be placed on top of the stack once the action is executed. Validation will also be performed on this model object, instead of the action.
    public class ModelDrivenAction implements ModelDriven { 
        public String execute() throws Exception {
            return SUCCESS;
        }    public Object getModel() {
            return new Gangster();
        }
    }
    public class Gangster implements Serializable {
        private String name;
        private int age;
        private String description;
        private boolean bustedBefore;.......<s:form action="modelDrivenResult" method="POST" namespace="/modelDriven">   
        <s:textfield label="Gangster Name" name="name" />
        <s:textfield label="Gangster Age"  name="age" />
        <s:checkbox  label="Gangster Busted Before" name="bustedBefore" />
        <s:textarea  cols="30" rows="5" label="Gangster Description" name="description" />           
        <s:submit />
    </s:form>红色的实体是和你数据库对应的。页面是和红色实体对应的。这样不就对应起来了吗?参看struts-xx-all/struts-xx/docs/WW/model-driven.html说明。
      

  2.   

    额,居然是版主大大,先谢谢你了struts-xx-all/struts-xx/docs/WW/model-driven.html这个是什么?我貌似木有这个东西。。
        是不是jsp中只能提交一个表单(如果不用ajxa什么的话),那ModelDriven默认就和唯一的一个表单匹配上了?然后实体中的属性是根据form表单中的属性名字匹配的吗?
      

  3.   

    Struts 2 does not have "forms" like Struts 1 did. In Struts 2 request parameters are bound directly to fields in the actions class, and this class is placed on top of the stack when the action is executed哪个是你下的struts2的zip包内的目录。
      

  4.   

    ModelDriven不是和数据库对应,是和实体类对应。如果你action中实现了ModelDriven,页面中的控件会自动对应成实体类中的属性值。如上:页面中name=logonName和name=logonPwd的控件提交上action时,会自动帮你把页面的属性封装成对象。