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
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年J2EE,想转行做游戏图形渲染,需要学些什么
- hibernate如何加悲观锁
- s:select multiple="true" 不能实现多选
- 安了aptana插件,怎么找回熟悉的dynamic web project呢
- apache+struts+mysql报错,跪求解决!
- 天气预报程序 web servlet xfire
- 求救,为什么执行到executeQuery()线程就死掉了??
- 外国一家公司的一道超难推理面试题,如果你做对了,直接录取拿5K以上的工资不成问题!!!!!!
- 关于struts2框架中在页面中取action中的全局变量的问题。
- 大视频播放问题
- spring+struts+hibernate多表查询如何在JSP页面取值?
- hibernate级联查询问题
直接用action的url, 并且是forward, 这样你就可以得到了.
=>
<result name="success">/Owner/queryOwner.action </result>
楼主截止到2008-06-18 23:22:42的汇总数据:
发帖数:1
结贴数:0
结贴率: 0.00%
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
<result type="redirectAction" >
<param name="success"> /Owner/queryOwner.action</param>
<param name="OwnerName">OwnerName</param>
</result>
</action>
应该是这样的配的,不过可能写法也许有点问题,你查查webwork2的文档吧
你可以在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掉。
<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...
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
<!-- struts-sjiang.xml -->
showOrderfood?desk_id=${desk_id}&orderform_id=${orderform_id}
<!-- <param name="actionName">showOrderfood</param>-->
<!-- <param name="desk_id">${desk_id}</param>-->
<!-- <param name="orderform_id">${orderform_id}</param>-->
</result>
<result name="success" type="redirect" >/Owner/queryOwner.action? ownerName={ownerName}</result>
<result name="success" type="redirect" >/Owner/queryOwner.action? ownerName=${ownerName}</result>