是一个checkAction转到一个executeAction的应用有2个ActionForm,就说AActionForm和BActionForm吧
他们都有一个比如叫age的属性和相应的get/set方法具体配置如下(能省的我就省了)<action path="/check"
               type="checkAction"
               name="AActionForm"
               scope="session"
    <forward name="execute" path="/execute" />
</action><action path="/execute"
               type="executeAction"
               name="BActionForm"
               scope="session"
    <forward name="show" path="/show.jsp" />
</action>然后checkAction的里面就直接
return new ActionForward("execute");
executeAction的里面就直接
return new ActionForward("show");我的问题是:
提交check.do之后,转转转转到executeAction的show的ActionForward
我在show.jsp里面,用
<html:hidden name="BActionForm" property="age" />
是可以取得age这个值的可是这个值是提交到check的时候提交的,
为什么走了2个action还能在show.jsp里作为BActionForm的一个属性读出呢?是不是因为scrop是"session"的原因,把actionform放在了session里?但是第2个ActionForm已经是BActionForm了,而不是check.do的AActionForm了难道struts有什么特殊的操作?问题有点乱,敬请谅解

解决方案 »

  1.   

    scope="session"
    指定的是FormBean的作用域
      

  2.   


    谢谢您的解答可是name属性定义的名字已经是另一个了啊?
    我就是奇怪他是怎么把age从AActionForm的实例转移到BActionForm里面的
      

  3.   

    BActionForm中的age属性值是你调用check.do后,请求转发到path="/execute" 时候给设置的。
    咱们做么做,是不是更清晰:
    比如有两个jsp为a.jsp,b.jsp且假如a.jsp中有个input域name为age,,一个action为A,
    a.jsp提交后到A这个action中,action处理完成后转发到b.jsp,那么这是你在b.jsp中request.getParameter("age");同样能取到值,对吧。你说的那个和这个其实是一个意思。
      

  4.   


    您的意思是
    当checkAction里面return new ActionForward("execute");之后
    又发出了一个相当于“/execute.do?age=xx”的请求?如果是这样,那么这个“?age=xx”是怎么接上去的呢?
    (或者是post的话,是怎么设置的呢?)....稍等这个age是不是不是按照参数而是放到session里面传递的?
    也就是BActionForm里面的age属性是struts利用“session.getAttribute("age")”的方法取得的?
    (而AActionForm里面的是request.getParameter(“age”)取得的)那么scope指定的session到底是
    age这个parameter存在session里面呢?(现在好像应该是这个)
    还是AActionForm这个实例存在session里呢?(之前我以为是这个)我好像有点钻进牛角尖了呵呵
      

  5.   

    Action中的ActionForm都是通过反射设置了。当你从check跳到execute时,check的AForm的值会通过反射把属性名相同的值注入BForm对应的属性。原理应该是这样的。。
      

  6.   

    你也可以看看stucts源码,看看ActionForm的构建方式。。 应该有从页面获取值注入,也有从原请求获取对象属性注入。
      

  7.   

    是因为都有同样的age属性吧  之前set以后 值一直都在session里
      

  8.   

    你不是把拥有age属性的对象放入 Session中了 
    以后用的时候 都会有的 啊
      

  9.   


    你说的我理解,我主要是纠结在两个不同的action设置中,name属性的ActionForm名字是不同的这个问题上了
      

  10.   


    我原来以为放入session的是ActionForm的实例,
    现在看来实际上应该是使用了session.setAttribute()这样的方法但是,如果session中存的是age这个值,那么
    <html:hidden name="BActionForm" property="age" />
    这句话应该是从ActionForm实例中取得age这个值的吧?!也没有说要从session中取得啊难道是age和ActionForm的实例都放在session中了??!!下午忙完了去找找代码看看看来还是学艺不精啊,惭愧惭愧good luck to all
      

  11.   

    -----struts1 中央控制器actionservlet 是先读取struts-config.xml配置 
    它先查看mapping中的配置 把信息写到hashmap里 
    得到name(actionform名)以后它在scope里面找
    找不到就实例化一个
    找到了就reset 再set值---
    你的问题应该是 那俩个form中的setAge()方法相同的(即有相同属性) 你跳转的时候就把age这个属性带给了第二个form
      

  12.   


    也就是struts第一次执行checkAction的时候,
    把age放到AActionForm里的同时,
    看scope是session,就也把age放到了session里?是这样吗?
      

  13.   

     public static ActionForm createActionForm(HttpServletRequest request,
            ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet servlet) {
            // Is there a form bean associated with this mapping?
            String attribute = mapping.getAttribute();        if (attribute == null) {
                return (null);
            }        // Look up the form bean configuration information to use
            String name = mapping.getName();
            FormBeanConfig config = moduleConfig.findFormBeanConfig(name);        if (config == null) {
                log.warn("No FormBeanConfig found under '" + name + "'");            return (null);
            }        ActionForm instance =
                lookupActionForm(request, attribute, mapping.getScope());        // Can we recycle the existing form bean instance (if there is one)?
            if ((instance != null) && config.canReuse(instance)) {
                return (instance);
            }        return createActionForm(config, servlet);
        } private static ActionForm lookupActionForm(HttpServletRequest request,
            String attribute, String scope) {
            // Look up any existing form bean instance
            if (log.isDebugEnabled()) {
                log.debug(" Looking for ActionForm bean instance in scope '"
                    + scope + "' under attribute key '" + attribute + "'");
            }        ActionForm instance = null;
            HttpSession session = null;        if ("request".equals(scope)) {
                instance = (ActionForm) request.getAttribute(attribute);
            } else {
                session = request.getSession();
                instance = (ActionForm) session.getAttribute(attribute);
            }        return (instance);
        }附上Structs源码:Structs先从配置得到String attribute = mapping.getAttribute();
    然后调用 ActionForm instance =
                lookupActionForm(request, attribute, mapping.getScope());
    到作用域寻找是否有相应ActionFormif ("request".equals(scope)) {
                instance = (ActionForm) request.getAttribute(attribute);
            } else {
                session = request.getSession();
                instance = (ActionForm) session.getAttribute(attribute);
            }
    是到request或者session根据attribute去得值的。
    你的配置文件没给attributte配值。所以第二个action中去通过attribute取时取的是前一个的值