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 (默认) ...
随机推荐
- ABP文档笔记 - 规约
ABP框架 - 规约 简介 规约模式是一个特别的软件设计模式,业务逻辑可以使用boolean逻辑重新链接业务逻辑(维基百科). 实践中的大部分情况,它是为实体或其它业务对象,定义可复用的过滤器. 理解 ...
- LintCode题解之最长单词
这些一次遍历搞定的,套路无非都是在遍历的时候就记录数据的状态,然后根据遍历到的当前的数据的状态来修改最终结果,当遍历完了的时候结果也就确定了. public class Solution { /* * ...
- SQL Server AlwaysON从入门到进阶(2)——存储
本文属于SQL Server AlwaysON从入门到进阶系列文章 前言: 本节讲解关于SQL Server 存储方面的内容,相对于其他小节而言这节比较短.本节会提供一些关于使用群集或者非群集系统过程 ...
- iOS关于时间的处理
转自:iOS关于时间的处理 做App避免不了要和时间打交道,关于时间的处理,里面有不少门道,远不是一行API调用,获取当前系统时间这么简单.我们需要了解与时间相关的各种API之间的差别,再因场景而异去 ...
- MyEclipse中查看struts_spring_hibernate源码
1.spring查看源码 首先下载对应的源码包 如:spring-framework-2.5.6-with-dependencies.zip 打开spring-framework-2.5.6\di ...
- Swift3的playground中对UI直接测试支持的改变
我们知道在Xcode的playground中不仅可以测试console代码,还可以测试UI代码,甚至我们可以测试SpriteKit中的场景,有兴趣的童鞋可以看我之前写的这一篇blog: Xcode的p ...
- Swift基础之UIPickerView和小animate的使用
写一个简单的UIPickerView的使用Demo,比较简单,其中和一个小动画的结合使用 UIPickerView的使用基本上跟OC语言中的一样,就是写法的样式问题,想必开发过OC的应该不需要多讲了, ...
- windows curl命令详解
概述 Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令. 软件下载 下载地址:https://cur ...
- 用scheme最基本的元素定义排序函数
用到的元素有9个: define,if,null?,cons car,cdr,lambda,let,named let, 其实let 和 named let可以去掉.但那样会带来性能和可读性下降的问题 ...
- [extjs5学习笔记]第三十七节 Extjs6预览版都有神马新东西
本文在微信公众号文章地址:微信公众号文章地址 本文地址:http://blog.csdn.net/sushengmiyan/article/details/45190485 [TOC] 在Ext JS ...