Struts Chain ClassCastException Aop
我们知道struts的restult type 有很多,但主要就是四种
dispatch,rediret,chain,drdirectaction
要让数据从一个action传到另一个action,就只能使用后两种,即chain与redirectaction(后来发现rediret也可以,网上说使用redirect的时候得加上扩展名例如,login.acion等等,可我发现,不加也OK)。
可能是因为,我的过滤器是这么写的
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这俩的区别如下:
先说chain,如果resulttype为chain,如果第一个action(我们暂且称为actionFraom)里面有有个成员变量叫name,而且第二个action(称为actionTo)里面也有个变量叫name,那么第二个action里面的值会复制第一个action。
public class ClassFrom {
private String name;
private String transFormLocation;
public String execute(){
setTransFormLocation("classTo");
System.out.println("i am classfrom");
System.out.println(name+" name");
return "success";
}
//省略getset
}
public class ClassTo {
private String name;
private String other;
public String execute(){
System.out.println("I am classto");
System.out.println(name+" name to");
System.out.println(other+" other to");
return "success";
}
//省略getset方法
}
如果,actionTo里面有个变量叫other,我想让它也复制actionFrom里name的值,下面这种写法是不行的
<package name="sdf" namespace="/modules" extends="struts-default">
<action name="classFrom" class="com.bufoon.action.ActionFrom" >
<result name="success" type="chain">
<param name="actionName">classTox</param>
<param name="other">${name}</param>
</result>
</action>
<action name="classTox" class="com.bufoon.action.ActionTo" >
<result>../result.jsp</result>
</action>
</package>
上面的情况下,actionto里面的other的值为null
但是actionfrom与actionto里同名的变量name的值是统一的(如果非要在actionto里用other获得值,让它自己找actionto里的name要)
如果使用redirectAction,那么情况刚刚相反,
actionTo里面的other获得了actionFrom里name的值
但是actionTo里面的name却为null
结论
1 基本都用chain吧 能满足你传值的需要(前提是两个action的变量是一致的)
2 如果用redirectaction 就得手动在xml里写param
更多资料见
http://blog.csdn.net/yujielu2012/article/details/8188383
以上为基础知识
****************************
今天在做项目的时候,发现一个搞不明白的问题。
首先,项目采用的是ssh,事务我采用的是xml的声明式事务管理。
ClassFrom与ClassTo的execute方法就等于是在一个事务里的。
struts的配置文件如下:
<package name="sdf" namespace="/modules/file_gxb/createFile" extends="struts-default">
<action name="classFrom" class="cdm.module.file.gxb.action.ClassFrom" >
<result type="chain">classTox</result>
</action>
<action name="classTox" class="cdm.module.file.gxb.action.ClassTo" >
<result>../../../result.jsp</result>
</action>
</package>
结果报了下面的错误
java.lang.ClassCastException: cdm.module.file.gxb.action.ClassFrom cannot be cast to cdm.module.file.gxb.action.ClassTo
cdm.module.file.gxb.action.ClassTo$$FastClassByCGLIB$$43d16e6a.invoke()
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
cdm.module.file.gxb.action.ClassTo$$EnhancerByCGLIB$$90aba811.execute()
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
刚开始,我还以为是自己对struts的传值理解的不清楚,就找了些资料,写了本篇博客的前半部分。
可是前面,action不管值能不能传递,最起码不会说ClassCastException呀。
最后仔细分析了错误,发现有aop的问题。
最后把chain改成了redirectAction 就一切OK了。
但是,此时两个action就不在一个事务里了
目前我没有更好的办法
问题就在aop里。
但是这里面更深层次的东西,估计得看源码才能解决了。
结论:
出了bug不要急,仔细看看异常的输出栈
Struts Chain ClassCastException Aop的更多相关文章
- org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.
No action config found for the specified url url路径下找不到action,原因是stuts-config.xml文件配置错误. demo的项目文件如下: ...
- 尚学堂马士兵struts2 课堂笔记(四)
27 结果类型 主要就四种种 dispatch和rediret chain和drdirectaction <package name="resultTypes" namesp ...
- struts框架学习过程中的问题
1,错误: java.lang.NullPointerException: Module 'null' not found.错误原因,struts运行需要的.jar文件拷贝不足,应该把它们加入到cla ...
- 【struts 报错】 No action config found for the specified url
1 type Exception report message org.apache.struts.chain.commands.InvalidPathException: No action con ...
- 使用Hibernate+MySql+native SQL的BUG,以及解决办法
本来是mssql+hibernate+native SQL 应用的很和谐 但是到了把mssql换成mysql,就出了错(同样的数据结构和数据). 查询方法是: String sql = " ...
- S2SH+mysql-软件开发实际部署问题-8个小时后提示MYSQL数据库无法连接
type Exception report message description The server encountered an internal error () that prevented ...
- Struts1的核心对象
1.ActionServlet.ActionMapping.ActionForm.ActionForward 2.config = "/WEB-INF/struts-config.xml&q ...
- Spring day03笔记
spring day02回顾 AOP :切面编程 切面:切入点 和 通知 结合 spring aop 编程 <aop:config> 方法1: <aop:pointcut expre ...
- struts2的result的type属性
一共有两个属性name和type name这里就不介绍了 type 返回结果的类型,值可以从default-struts.properties中看到看到 常用的值:dispatcher (默认) ...
随机推荐
- 利用生产者消费者模型和MQ模型写一个自己的日志系统-并发设计里一定会用到的手段
一:前言 写这个程序主要是用来理解生产者消费者模型,以及通过这个Demo来理解Redis的单线程取原子任务是怎么实现的和巩固一下并发相关的知识:这个虽然是个Demo,但是只要稍加改下Appender部 ...
- pycharm 安装与基本设置
一.下载及安装 打开官网下载:https://www.jetbrains.com/pycharm/download/#section=windows 下载完毕之后可直接双击可执行文件,然后点击&quo ...
- Docker 容器格式
最初,Docker 采用了 LXC 中的容器格式.自 1.20 版本开始,Docker 也开始支持新的 libcontainer 格式,并作为默认选项. 对更多容器格式的支持,还在进一步的发展中.
- Unity使用UGUI进行VR游戏的界面开发
原文链接:http://gad.qq.com/article/detail/7181505 本文首发腾讯GAD开发者平台,未经允许,不得转载 我不知道有多少同学是跟我一样,在开发VR游戏中,是使用的面 ...
- Oracle性能优化-读懂执行计划
Oracle的执行计划 得到执行计划的方式 Autotrace例子 使用Explain explain plan set STATEMENT_ID='testplan' for select * fr ...
- Linux-2.6.25 TCPIP函数调用大致流程
插口层系统调用send sys_send sys_sendtosendto sys_sendto sock_sendmsgsendmsg sys_send ...
- 动手试试Android Studio插件开发
由于业务关系,经常需要写一些表单页面,基本也就是简单的增删改查然后上传,做过几个页面之后就有点想偷懒了,这么低水平重复性的体力劳动,能不能用什么办法自动生成呢,查阅相关资料,发现android stu ...
- J2EE进阶(十四)超详细的Java后台开发面试题之Spring IOC与AOP
J2EE进阶(十四)超详细的Java后台开发面试题之Spring IOC与AOP 前言 搜狐畅游笔试题中有一道问答题涉及到回答谈谈对Spring IOC与AOP的理解.特将相关内容进行整理. ...
- Android全屏截图的方法,返回Bitmap并且保存在SD卡上
Android全屏截图的方法,返回Bitmap并且保存在SD卡上 今天做分享,需求是截图分享,做了也是一个运动类的产品,那好,我们就直接开始做,考虑了一下,因为是全屏的分享,所有很自然而然的想到了Vi ...
- [struts2学习笔记] 第六节 struts2依赖的jar包还有Could not find action or result 错误解决
本文地址:http://blog.csdn.net/sushengmiyan/article/details/43272061 本文作者:sushengmiyan ------------------ ...