org.apache.struts2.json.JSONWriter can not access a member of class
偶遇一个问题:org.apache.struts2.json.JSONWriter can not access a member of class
org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
with modifiers "public"。困扰了半天,找到了解决方案,写写自己的一些理解。
action代码:

1 package edu.bjfu.action;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.annotation.Resource;
7
8 import org.apache.struts2.json.annotations.JSON;
9
10
11 import com.opensymphony.xwork2.ActionSupport;
12
13 import edu.bjfu.entity.Authority;
14 import edu.bjfu.service.AuthorityService;
15
16 public class AuthoritiesAction extends ActionSupport{
17 private AuthorityService authorityService;
18 private List<Authority> authorities;
19
20 public List<Authority> getAuthorities() {
21 return authorities;
22 }
23
24 public void setAuthorities(List<Authority> authorities) {
25 this.authorities = authorities;
26 }
27 public AuthorityService getAuthorityService() {
28 return authorityService;
29 }
30
31 @Resource(name="authorityService")
32 public void setAuthorityService(AuthorityService authorityService) {
33 this.authorityService = authorityService;
34 }
35
36 public String execute() throws Exception {
37 authorities=authorityService.getAllAuthorities();
38 return SUCCESS;
39 }
40
41 }

配置文件代码:
1 <package name="super_admin" extends="json-default" namespace="/superadmin">
2 <action name="allAuthorities" class="edu.bjfu.action.AuthoritiesAction">
3 <result type="json"></result>
4 </action>
5 </package>
ajax交互代码:

1 $(function(){
2 $.post("superadmin/allAuthorities?dt="+new Date().getTime(),
3 function(data){
4 $("#authority").empty();
5 var json = eval(data);
6 for(var i=0;i<json.length;i++){
7 $("#authority").append("<option value='"+json[i].authorityId+"'>"+json[i].authorityName+"</option>");
8 }
9 },"json")
10 })

这样每次在交互的时候就会发生以上错误。
主要原因:struts会将action中定义的一些变量序列化转换成json格式,需要调用对象的一系列get方法(例子中调用authorityService和authorities的get方法),并调用以上两个变量的成员变量的get方法将其内容组成json格式。但是在序列化authorityService时,由于其成员变量中含有含有接口所以会报错。
解决方案:
1)修改配置文件:指定序列化的根节点,这样data就是从authorities的根节点以下的数据,不需要用data.authorities
1 <package name="super_admin" extends="json-default" namespace="/superadmin">
2 <action name="allAuthorities" class="edu.bjfu.action.AuthoritiesAction">
3 <result type="json"><param name="root">authorities</param></result>
4 </action>
5 </package>
2) 修改java代码:让编译器不对authorityService序列化
1 @JSON(serialize=false)
2 public AuthorityService getAuthorityService() {
3 return authorityService;
4 }
3)此外貌似可以通过配置文件的excude和include来指定需要序列化的对象,我没有自己去试!
org.apache.struts2.json.JSONWriter can not access a member of class的更多相关文章
- Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
Spring注入Action使用Json错误:org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: ...
- Class org.apache.struts2.json.JSONWriter can not access a member of
异常形式: Class org.apache.struts2.json.JSONWriter can not access a member of * 或是 Class com.googlecode. ...
- Class org.apache.struts2.json.JSONWriter can not access a member of class oracle.jdbc.driver.Physica
产生这个错误的原因是因为我的oracle数据库中有一个CLOB字段,查询出来的时候要转换为JSON而报错. Class org.apache.struts2.json.JSONWriter can n ...
- 解决json结合struts2时,Class org.apache.struts2.json.JSONWriter can not access a member of * 的问题
在使用json的时候,产生的一个错误,查了一下资料,原来是struts2和json一起使用的时候,才产生的问题,虽然不影响程序的运行,但是总是会有一些异常的日志产生,并且,这个也会增加程序的负担. 原 ...
- struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter
1. 问题描述: 页面通过异步访问action, action的方法通过map封装数据,struts的result的type设置为json,后台报错 六月 25, 2016 6:54:33 下午 ...
- Struts2 项目 Action 查询结果异常 org.apache.struts2.json.JSONException
问题描述 今天进行一个订单管理模块的开发时遇到一个问题:查询的订单时有时会报这个异常: org.apache.struts2.json.JSONException: java.lang.Illegal ...
- root cause:org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
今天在调试SSH与Ajax时,服务器端报出JSON异常:
- EXT4+Struts2 JSON的问题
ERROR : Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframewor ...
- struts2 json 定义全局Date格式
使用struts2的json插件时,自己定义日期格式经常使用的方式是在get属性上加入@JSON注解,这个对于少量Date属性还能够,可是假设date字段多了,总不可能去给每一个date get方法加 ...
随机推荐
- opencv学习笔记(六)直方图比较图片相似度
opencv学习笔记(六)直方图比较图片相似度 opencv提供了API来比较图片的相似程度,使我们很简单的就能对2个图片进行比较,这就是直方图的比较,直方图英文是histogram, 原理就是就是将 ...
- 菜鸟学Linux命令:ssh命令 远程登录
1.查看SSH客户端版本 有的时候需要确认一下SSH客户端及其相应的版本号.使用ssh -V命令可以得到版本号.需要注意的是,Linux一般自带的是OpenSSH: 下面的例子即表明该系统正在使用Op ...
- display : -webkit-box-inline 的理解
发现: 最近在做移动端的东西,说起移动端弹性盒子布局真是无往不利,用起来特别爽,我也是偶尔间发现的这个属性并且它的用法,在网上基本查不到这个属性的资料(个人看法).如果没有听说过(display:bo ...
- 面向服务的体系结构(SOA)——(1)目标与核心概念
什么是SOA? 常常听到人们拿OOP和SOA一起来说事,诸如SOA是否可以代替面向对象(OOP)或者两者比哪个更加有优势?直接回答有难度举个例子可能显得答案更容易理解.小孩子问你该认真写作业呢?还是高 ...
- poj 2635 千进制
转自:http://www.cnblogs.com/kuangbin/archive/2012/04/01/2429463.html 大致题意: 给定一个大数K,K是两个大素数的乘积的值. 再给定一个 ...
- 实例讲解虚拟机3种网络模式(桥接、nat、Host-only)
转自:http://www.cnblogs.com/ggjucheng/archive/2012/08/19/2646007.html 前言 很多人安装虚拟机的时候,经常遇到不能上网的问题,而vmwa ...
- Codeforces Round #352 (Div. 2) D. Robin Hood 二分
D. Robin Hood We all know the impressive story of Robin Hood. Robin Hood uses his archery skills a ...
- loj 1165(bfs+康托展开)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26879 思路:题目意思很简单,就是通过一些位置的交换,最后变成有序 ...
- 使用jQuery实现类似开关按钮的效果
转自:http://www.cnblogs.com/linjiqin/p/3148228.html 本案例实现类似开关按钮效果. 页面有下拉列表.文本框.按钮等表单元素,大致实现如下效果:1.页面一加 ...
- HDU3996 Gold Mine(最大权闭合子图)
#include<cstdio> #include<cstring> #include<queue> #include<algorithm> using ...