action1里面的代码:
public class PetAction extends ActionSupport {
private String ownerName;public String getOwnerName() {
        return ownerName;
}public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}public String linkOwner() {
setOwnerName(ownerName);
return SUCCESS;
}
}action2里面的代码:
ublic class OwnerAction extends ActionSupport {
private String ownerName;public String getOwnerName() {
        return ownerName;
}public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}public String queryOwner() {
       System.out.println(ownerName);
       return SUCCESS;
}
}struts.xml配置:
<action name="linkOwner" class="com.xiaoji.petclinic.struts.PetAction" method="linkOwner" >
  <result name="success" type="redirectAction" >/Owner/queryOwner.action</result>
</action>
<action name="queryOwner" class="com.xiaoji.petclinic.struts.OwnerAction" method="queryOwner" >
        <result name="success">/Owner/showOwners.jsp</result>
</action>
我在queryOwner里面获取ownerName的值是null

解决方案 »

  1.   

    redirectAction表示redirect, 这样你是不能得到前面一个action中的request信息的. 
    直接用action的url, 并且是forward, 这样你就可以得到了. 
      

  2.   

    请问如何在action里面用forward 请把代码写出来吗谢谢
      

  3.   

    <result name="success" type="redirectAction" >/Owner/queryOwner.action </result> 
    =>
    <result name="success">/Owner/queryOwner.action </result> 
      

  4.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主截止到2008-06-18 23:22:42的汇总数据:
    发帖数:1
    结贴数:0
    结贴率: 0.00%
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  5.   

    能得到值的,不过要在structs.xml文件里面配好。<action name="linkOwner" class="com.xiaoji.petclinic.struts.PetAction" method="linkOwner" > 
             <result type="redirectAction" >
                 <param name="success"> /Owner/queryOwner.action</param>
                 <param name="OwnerName">OwnerName</param>
            </result> 
    </action> 
    应该是这样的配的,不过可能写法也许有点问题,你查查webwork2的文档吧
      

  6.   

    搂主,按你的struts.xml中的配置方法。可以得到参数。
    你可以在action1里把参数放到session 里,然后在action2里从session里接收。
    struts2的action中得到session的方法如下: 
    import com.opensymphony.xwork2.ActionContext类,通过它的静态方法getContext()获取当前Action的上下文对象。然后获取session.
    action1中:
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        session.put("userName","Tom");
    Struts2中的session都被封装成了Map类型。
    类似的,action2中:
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        String username = (String) session.get("userName");
    另外,注意不再使用的信息及时的从session中remove掉。
      

  7.   

    type="redirect"还有type="redirectAction",都是请求参数全部丢失,action参数也全部丢失,所以一般如果要传参数的话,不会用这2中type,而是用chain====> chain:action处理完后转发到一个action,请求参数全部丢失,action处理结果不会丢失。 所以你可以这么配置<action name="linkOwner" class="com.xiaoji.petclinic.struts.PetAction" method="linkOwner" > 
     <result name="success" type="chain">/Owner/queryOwner.action</result> 
    </action>
    <action name="queryOwner" class="com.xiaoji.petclinic.struts.OwnerAction" method="queryOwner" > 
     <result name="success">/Owner/showOwners.jsp </result> 
    </action>然后 执行linkOwner.action...
      

  8.   

    G'day,I appear to have resolved this issue that I kept running into with the 
    Jasper Reports plugin...If I have an action defined as:        <action name="foo_*" method="{1}" class="com.xxx.foo">
                <result name="success" type="jasper">
                  <param name="location">WEB-INF/foo.jasper</param>
                    <param name="format">${contentType}</param>
                  <param name="dataSource">dataSource</param>
                  <param name="imageServletUrl">/servlets/image?image=</param>
                  </result>            
            </action>
    Using the Jasper Reports plugin that ships with S2 current, I get:16:02:13,220 WARN  [OgnlUtil] Caught OgnlException while setting 
    property 'imageServletUrl' on type 
    'org.apache.struts2.views.jasperreports.JasperReportsResult'.
    java.lang.IllegalAccessException: Class ognl.OgnlRuntime can not access 
    a member of class 
    org.apache.struts2.views.jasperreports.JasperReportsResult with 
    modifiers "protected"
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
        at java.lang.reflect.Field.doSecurityCheck(Field.java:960)
        at java.lang.reflect.Field.getFieldAccessor(Field.java:896)
        at java.lang.reflect.Field.set(Field.java:657)
        at ognl.OgnlRuntime.setFieldValue(OgnlRuntime.java:1140)
    ...And the imageServletUrl param does not take effect.The issue appears to be that all of the setters in JasperReportsResult 
    return a JasperReportsResult.  The JavaBeans spec identifies that the 
    setter for a simple property must return void.  As a result, 
    BeanInfo.getPropertyDescriptors won't see these setters as write methods 
    for properties.  With the other props in this class, that's not a 
    problem - since they don't have getters, we don't get any 
    propertyDescriptors for the properties, and proceed to look for methods 
    individually (OgnlRuntime.java:1296).  For imageServletUrl, however, 
    there _is_ a valid getter.  BeanInfo sees this as a read-only prop and 
    returns a property descriptor for it, showing exactly that.  Back in 
    OGNL code, we see that we got a PropertyDescriptor, and don't bother 
    asking for all methods.  getSetMethod says "I don't have a set method," 
    so OGNL eventually tries to just poke the field, resulting in the above 
    error because the field is protected.Solution: modify the setters in JasperReportsResult to return void.  
    This has been confirmed to fix the above problem.PK
      

  9.   

    <result name="showorder" type="redirectAction">
    <!-- struts-sjiang.xml -->
    showOrderfood?desk_id=${desk_id}&amp;orderform_id=${orderform_id}
    <!-- <param name="actionName">showOrderfood</param>-->
    <!-- <param name="desk_id">${desk_id}</param>-->
    <!-- <param name="orderform_id">${orderform_id}</param>-->
    </result>
      

  10.   

    俺一般这样写:
    <result name="success" type="redirect" >/Owner/queryOwner.action? ownerName={ownerName}</result>  
      

  11.   

    少了$符号:
    <result name="success" type="redirect" >/Owner/queryOwner.action? ownerName=${ownerName}</result>