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方法加 ...
随机推荐
- 安装qmake与环境变量解析
转自:http://www.kuqin.com/qtdocument/qmake-manual-2.html 安装qmake 当Qt被连编的时候,默认情况下qmake也会被连编. 这一部分解释如何手工 ...
- Hibernate常见问题
问题1,hql条件查询报错 执行Query session.createQuery(hql) 报错误直接跳到finally 解决方案 加入 <prop key="hibernate.q ...
- export 解决环境变量的问题!!!!
export PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin" 如果/et ...
- 实例讲解虚拟机3种网络模式(桥接、nat、Host-only)
转自:http://www.cnblogs.com/ggjucheng/archive/2012/08/19/2646007.html 前言 很多人安装虚拟机的时候,经常遇到不能上网的问题,而vmwa ...
- loj 1155(最大流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26869 思路:题目还是比较水的,由于点也有容量,则必须拆点,然后跑 ...
- Beaglebone Black的启动
Beaglebone Black的启动 第1章 准备开始 Beaglebone Black上最显眼的恐怕就是板子两侧的扩展端口,一侧有46个端口,共92个端口Beaglebone Black的启动. ...
- Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- DataMember IsRequired属性
1.简介 在数据契约中,如果需要序列化时,则需要传入指定IsRequired属性: 摘要: 获取或设置一个值,该值用于指示序列化引擎在读取或反序列化时成员必须存在. public bo ...
- vnc使用
使用rpm –qa vnc命令如果收到如下信息说明已经安装了vncserver, [root@localhost: ~]#rpm -qa |grep vnc gtk-vnc-python--.el5 ...
- CentOS6.4 配置HAProxy+Keepalived
安装HAProxy请参考 http://www.cnblogs.com/kgdxpr/p/3272861.html 安装Keepalived 1.下载安装依赖包 yum install -y wget ...