今天做了SSH2框架下的Ajax从后台去处List返回前台,数据取成功了,前台也可以显示,但总会报错如下:java.lang.IllegalAccessException: Class com.googlecode.jsonplugin.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers "public"
ERROR [http-8080-3] [default].invoke(253) | Servlet.service() for servlet default threw exception
java.lang.IllegalAccessException: Class com.googlecode.jsonplugin.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:222)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:159)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:159)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:125)
at com.googlecode.jsonplugin.JSONWriter.write(JSONWriter.java:93)
at com.googlecode.jsonplugin.JSONUtil.serialize(JSONUtil.java:96)
at com.googlecode.jsonplugin.JSONResult.execute(JSONResult.java:175)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:343)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:213)
:188)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
上网查了好久,说是因为有类型不能序列化,所以爆出此错,网上说的两个解决方法:
1. 将不能序列化的方法的get方法删去
2. 在此get方法前加入注解@JSON(serialize=false)强制其不进行序列化。
在我用的SSH2中,显然不能用第一种方式,因为报错的,就是因为一些application.xml中Spring依赖注入的一些业务逻辑类不能序列化,利用DataManager,MessageManager这样一些Manager,删去get方法,去new XXXManager显然将Spring带来的方便和好处抛弃了,所以:
找到当前action在spring配置文件中以来的业务逻辑类,然后在action类中找到这些所对应的get方法,如public XXManager getXXXManager(){}在其前面加上@JSON(serialize=false)即可,注意set不用加
分享到:
相关推荐
介绍struts、ajax如何返回json数据 一首先引入Struts和json所需的jar包。 二编写页面 三编写action类 四Struts配置
Struts2+ajax+json返回list,并处理json返回为[object,object]的方法,Struts2配置
struts2返回json数据类型
利用AJAX传递JSON数组,后台struts2的action接收。 详细代码简单易懂。
很多人在实现struts使用ajax返回json数据的时候,明明代码没有错误但是没有得到结果,其实有可能是jar包冲突或者少了,这里我分享ssh的所有jar包,可以直接部署使用,如果部署有问题的可以看下我的说明文档,本来想...
如果是作为客户端的HTTP+JSON接口工程,没有JSP等view视图的情况下,使用Jersery框架开发绝对是第一选择。... Struts2返回JSON有两种方式:1.使用Servlet的输出流写入JSON字符串;2.使用Struts2对JSON的扩展。
json2+jsonplugin struts2整合ajax时,使用json时需要的jar包。。。。。。。。。。。。
当自己做出来时,感觉挺简单的,但想起自己刚开始做不会那会儿,真的挺悲哀的啊,在网上也搜了半天也没搜出个123,最终经过苦战终于做出来的,文档中重要部分都标红提示了,在此分享给童鞋们
Struts2 Jquery ajax Json实现的一个完整案例
struts-ajax-json-struts开发需要的jar包。
关键代码都在里面 资源是工程中的一部分 暂不能运行 原来用的是Java实现Json串 考虑到频繁访问数据库 就改成了存储过程
struts2 ajax json所需要的jar包
该资源是使用struts2框架进行操作,返回json格式数据,前台通过ajax提交内容。
Struts2 与Jquery Ajax的json数据交换的典型范例
Struts2+JSON_实现AJAX_返回对象和列表
androind http 请求 struts2 action 返回 json 数据 例子
通过struts2返回json数据类型很好的文档里面有例子说明的
JQuery发送Ajax请求Struts2,并返回JSON的例子。该例子对应 http://blog.csdn.net/littleqiang520中的博文
struts2+ajax+json需要的jar包:commons-beanutils-1.8.0.jar commons-lang-2.5.jar ezmorph-1.0.6.jar json-lib-2.4-jdk15.jar struts2-core-2.0.14.jar jsonplugin-0.32.jar
struts2.3.20生成返回json 浏览器解析json!