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方法加 ...
随机推荐
- 解决Tomcat 6.0 只支持 J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
通过search,发现在project的.setting folder下面,有个名为org.eclipse.wst.common.project.facet.core.xml的文件,里面配置有各种版本 ...
- w
w --help -f 开启或关闭显示用户从何处登入系统. -h 不显示各栏位的标题信息列. -l 使用详细格式列表,此为预设值. -s 使用简洁格式列表,不显示用户登入时间,终端机阶段作业和程序所耗 ...
- MySQL错误:Every derived table must have its own alias
Every derived table must have its own alias 派生表都必须有自己的别名 一般在多表查询时,会出现此错误. 因为,进行嵌套查询的时候子查询出来的的结果是作为一个 ...
- mysql导入出现MySQL Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes
解决办法: 就搞定了.
- .NET 下各种Resource的读取方式
1) Embedded Resource (Build Action 设置为 Embedded Resource) 在运行时使用GetManifestResourceStream读取 Image.Fr ...
- [杂] ASP.NET MVC 之 Route To MvcHandler
首先,本文参考了不少东东,仅供Q_L_H自己使用,ZZ自己负责.先上一张全家福: HttpModules and HttpHandlers ASP.NET MVC 是 HttpHandler. Url ...
- 基于JQuery实现滚动到页面底端时自动加载更多信息
基于JQuery实现滚动到页面底端时自动加载更多信息 关键代码: 代码如下: var stop=true; $(window).scroll(function(){ totalheight = par ...
- Visual Studio 2015和ASP.NET 5中可用的前端开发工具集
最近微软发布了一本白皮书,谈到了一些可以和Visual Studio 2015和ASP.NET 5配合使用的JS/前端Web开发工具(比如:函数库.任务执行器.框架等). 由于现在前端开发的生态系统在 ...
- Web应用你加盐了吗?——浅谈MD5加密算法中的加盐值(SALT)
转自:http://blog.csdn.net/blade2001/article/details/6341078 我们知道,如果直接对密码进行散列,那么黑客可以对通过获得这个密码散列值,然后通过查散 ...
- Java和Android注释规范
1. 文件头注释 每一个文件的文件头都必须做文件头注释.文件头注释范例如下: /* * 文件名:LoginActivity * 描 述:对用户 * 作 者: * 时 间: * 版 权: */ 2. ...