合并不了,最简单的就是在actionForm中声明一个实体bean的变量,顺便要进行初始化
public class XxxForm{
private User user;
{
   user = new User();
}
......
}

解决方案 »

  1.   

    把POJO类继承下ActionForm好象就好.记得以前是这样做的
    在XML里再配置一下..不过这样不好吧.结合的就紧密了
      

  2.   

    ActionForm在struts的ActionServlet中要进行一些初始化配置吧,如果继承了他,还能叫pojo了吗
      

  3.   


    赞成,actionForm一直以来就是争论的焦点,也是struts1的诟病,还是用struts2吧,架构在webwork上,很好的解决了formbean 和实体bean的关系。
      

  4.   

    用struts2吧,没有这个问题,如果一定要用struts1的话,也可以做个bean to form ,form to bean的转化工具类,也许还行吧,
    我做过不过也许不太好import java.lang.reflect.Method;
    import java.util.Hashtable;
    import java.util.Iterator;import org.apache.struts.action.ActionForm;/**
     * @author Flying11 E-mail:[email protected]
     * Apr 14, 2008 10:51:52 PM
     */public class BeanToForm<T extends Object, F extends ActionForm> implements Cloneable{
    /**
     * the method base on the fact that the bean's all methods is strictly observe java beans agreement  
     * @param f the source bean
     * @param t the objective bean
     * @return if they are successfully transformed,return true;else false
     */
    private static boolean transform(Object f, Object t) {
    try {
    // put f to hashtable
    Method[] temp = Class.forName(f.getClass().getName()).getMethods();
    Hashtable<String, Method> from = new Hashtable<String, Method>(); for (int len = 0; len < temp.length; len++) {
    if (temp[len].getName().startsWith("get")
    && temp[len].getParameterTypes().length == 0) {
    from.put(temp[len].getName().substring(1), temp[len]);
    }
    }
    // put t to hashtable
    temp = Class.forName(t.getClass().getName()).getMethods();
    Hashtable<String, Method> to = new Hashtable<String, Method>();
    for (int len = 0; len < temp.length; len++) {
    if (temp[len].getName().startsWith("set")
    && temp[len].getParameterTypes().length == 1) {
    to.put(temp[len].getName().substring(1), temp[len]);
    }
    }
    Iterator<String> it = from.keySet().iterator();
    while (it.hasNext()) {
    String key = it.next();
    if (to.containsKey(key)
    && to.get(key).getParameterTypes()[0].equals(from.get(
    key).getReturnType())) {
    to.get(key).invoke(t, from.get(key).invoke(f));
    }
    }
    return true;
    } catch (Exception e) {
    throw new RuntimeException(e);
    }
    }
    /**
     * the method base on the fact that the bean's all methods is strictly observe sun javabean agreement
     * @param <AF>  extends org.apache.struts.action.ActionForm
     * @param <O>   extends java.lang.Object
     * @param bean bean to transform
     * @param form transformed bean
     * @return if they are successfully transformed,return true;else false
     */
    public static <AF extends ActionForm, O extends Object> boolean Bean2Form(
    O bean, AF form) {
    return transform(bean, form);
    }
    /**
     *  the method base on the fact that the bean's all methods is strictly observe sun javabean agreement
     * @param <AF>  extends org.apache.struts.action.ActionForm
     * @param <O>   extends java.lang.Object
     * @param form transformed bean
     * @param bean bean to transform
     * @return if they are successfully transformed,return true;else false
     */
    public static <AF extends ActionForm, O extends Object> boolean Form2Bean(
    AF form, O bean) {
    return transform(form, bean);
    }
    }
      

  5.   

    public class UserForm extends ActionForm {
     private User user = new User();
     //setter
     //getter
    }
    Jsp<html:text size="10" property="user.name"></html:text>
      

  6.   

    User要new一下,要不报空指针异常
      

  7.   

    可以的,我测试过。
    你看看下面的介绍
    http://blog.csdn.net/guoquanyou/archive/2008/09/02/2866201.aspx
    http://blog.csdn.net/guoquanyou/archive/2008/09/06/2891477.aspx
      

  8.   

    要是觉得2个麻烦,一个也完全可以搞定,不过大点的项目有个实体类比较好,form始终属于表现层,把它弄到持久层不符合规范!
      

  9.   

    很简单的,你只要记清楚了和数据库打交道的一定是Hibernate自动生成的bean就好了,
    actionForm可以是动态的也可以是静态的,如果是静态的那么你别忘了从这个bean中取出
    表单值后还要放到Hibernate生成的bean中