偶遇一个问题: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的更多相关文章

  1. 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: ...

  2. 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. ...

  3. 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 ...

  4. 解决json结合struts2时,Class org.apache.struts2.json.JSONWriter can not access a member of * 的问题

    在使用json的时候,产生的一个错误,查了一下资料,原来是struts2和json一起使用的时候,才产生的问题,虽然不影响程序的运行,但是总是会有一些异常的日志产生,并且,这个也会增加程序的负担. 原 ...

  5. struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter

    1. 问题描述: 页面通过异步访问action,    action的方法通过map封装数据,struts的result的type设置为json,后台报错 六月 25, 2016 6:54:33 下午 ...

  6. Struts2 项目 Action 查询结果异常 org.apache.struts2.json.JSONException

    问题描述 今天进行一个订单管理模块的开发时遇到一个问题:查询的订单时有时会报这个异常: org.apache.struts2.json.JSONException: java.lang.Illegal ...

  7. root cause:org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException

    今天在调试SSH与Ajax时,服务器端报出JSON异常:

  8. EXT4+Struts2 JSON的问题

    ERROR : Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframewor ...

  9. struts2 json 定义全局Date格式

    使用struts2的json插件时,自己定义日期格式经常使用的方式是在get属性上加入@JSON注解,这个对于少量Date属性还能够,可是假设date字段多了,总不可能去给每一个date get方法加 ...

随机推荐

  1. MVC自带的校验

    一.添加控制器Home和Model数据 public class UserInfo { public int Id { get; set; } [Display(Name="用户名" ...

  2. 希尔排序( Shell Sort)

    原文地址:http://www.stoimen.com/blog/,在此感谢作者! Insertion sort is a great algorithm, because it’s very int ...

  3. HTTP协议中状态码的应用

    HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码. 所有状态码的第一个数字代表了响应的五种状态之一.   Mark from 维基百科     消息 ...

  4. jquery easy ui 1.3.4 数据表格(DataGrid)(8)

    8.1.创建DataGrid html代码 <table id="dg"></table> $("#dg").datagrid({ // ...

  5. HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)

    Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...

  6. Touch 事件的分发和消费机制

    Android 中与 Touch 事件相关的方法包括:dispatchTouchEvent(MotionEvent ev).onInterceptTouchEvent(MotionEvent ev). ...

  7. scp 使用

    [spark-hadoop@master ~]$ sudo scp /etc/profile spark-hadoop@slave1:/etc spark-hadoop@slave1's passwo ...

  8. 使用 Docker 建立 Mysql 集群

    软件环境介绍操作系统:Ubuntu server 64bit 14.04.1Docker 版本 1.6.2数据库:Mariadb 10.10 (Mariadb 是 MySQL 之父在 MySQL 被 ...

  9. C# Remoting的一个简单例子

    .Net对于远程调用提供了两种方法:Remoting和WebService.WebService现在是如火如荼,特别是有一种比较流行的架构:Winform+WebService(Java..Net), ...

  10. http://my.oschina.net/chinacion/blog/647641

    http://my.oschina.net/chinacion/blog/647641