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来指定需要序列化的对象,我没有自己去试!
转载于:https://www.cnblogs.com/telwanggs/p/5430151.html
org.apache.struts2.json.JSONWriter can not access a member of class相关推荐
- org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily i
数据转换成json数据失败,封装的实体类中有集合字段,在get方法上面加@JSON(serialize=false)注解 @JSON(serialize=false) public Set<Su ...
- org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException异常解决
org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException异常解决 参考文章: (1)org. ...
- 解决can not access a member of class xxx with modifiers ““问题
项目场景: 在QueryRunner封装bean时出现 java.sql.SQLException: Cannot create backstage.bean.Estate: Class org.ap ...
- 绿盟科技网络安全威胁周报2017.11 关注Apache Struts2 任意代码执行漏洞 CVE-2017-5638...
绿盟科技发布了本周安全通告,周报编号NSFOCUS-17-11,绿盟科技漏洞库本周新增136条,其中高危63条.本次周报建议大家关注 Apache Struts2 任意代码执行漏洞 CVE-2017- ...
- org.apache.struts2.dispatcher.FilterDispatcher的四个功能
org.apache.struts2.dispatcher.FilterDispatcher的四个功能 2008-05-24 11:16 1.org.apache.struts2.dispatcher ...
- Apache Struts2(S2-045)漏洞反思总结
2017的3.8-3.9号,Apache Struts2出现漏洞,该漏洞影响范围广,危害级别高.轻则系统文件感染,严重则系统瘫痪. 国家信息安全漏洞库(CNNVD)收到关于Apache Struts2 ...
- 问题解决:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
问题解决:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 参考文章: (1)问题解决:org.apache. ...
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter错误解决
一月 10, 2017 1:50:21 下午 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting f ...
- ava method org.apache.struts2.components.Form.getValidators(String) threw an exception when invoke
struts2校验框架 校验配置文件的DTD在xword-core-2.2.3.jar中,系统自带的校验器的xml配置文件是 xword-core-2.2.3.jar里com.opensymphony ...
最新文章
- final关键字最全了解
- Vue开发跨端应用(四)electron发布web应用并打包app
- [PM Tools]软件项目进度跟踪表v4.0
- java上传的文件没有,java – 文件未上传到服务器
- COM 组件设计与应用(十一)—— IDispatch 及双接口的调用
- 3、Eternal框架-控制器
- 学习手记(2021/3/19~?)
- 大数据实验报告总结体会_建设大数据中台架构思考与总结
- android 编译luajit,Android 嵌入 LuaJIT 的曲折道路
- 思科模拟器:网络安全实验
- 局域网屏幕共享_教学一体机多屏共享
- 生物特征识别:小面积指纹识别算法(二)
- SSI接口 AC97
- 最简单播放m3u8链接的方法
- java前端学习路线
- 【web前端面试题整理07】我不理解表现与数据分离。。。
- 重磅!!毕业将近,论文免费查重工具任你选,非常值得收藏!
- 【说透区块链系列】一文读懂什么是Web 3.0
- 部分彩色图片处理方式的C++实现
- Java破解9X9数独小游戏
热门文章
- 基于FPGA实现IIC接口(EEPROM)
- (02)Verilog HDL模块
- python堆排序算法_Python算法学习之堆和堆排序
- Linux内核分析 - 网络[十二]:UDP模块 - 收发
- 从程序员到项目经理(五):程序员加油站 -- 不是人人都懂的学习要点
- 用户借助操作系统使用计算机,计算机操作系统试题_B试卷及答案(08-09)
- jwt实现单点登录,基础讲解加实战!!!
- C++ 类的定义、作用域及大小计算,限定访问符,this指针
- linux无线网卡连不上网,Ubuntu 16.04无线网卡不见,无法用WiFi上网的解决方法
- const php 数组,php-如何在该类中创建类实例的const数组?