框架:struts2.0+hibernate2+spring

今天写代码时,需要用到json,我就直接加了两个jar包:json-lib-2.1-jdk15.jar,struts2-json-plugin-2.2.3.jar。启动不起来。我用的是struts-core-2.0.11.jar,很明显不兼容报错。后来我在网上找到可以用jsonplugin-0.32.jar。json插件在http://code.google.com/p/jsonplugin/downloads/list下载,注意版本。struts2.1以上版本要下载jsonplugin-0.34.jar否则会有问题。

网上说定义的package必须继承json-default。但当按"alt+/"时没有提示json-default,因为json-default中的代码是:

<package name="json-default" extends="struts-default">
        <result-types>
            <result-type name="json" class="org.apache.struts2.json.JSONResult"/>
        </result-types>
        <interceptors>
            <interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
        </interceptors>
    </package>

所以我直接把:

<result-types>
            <result-type name="json" class="org.apache.struts2.json.JSONResult"/>
        </result-types>
        <interceptors>
            <interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
        </interceptors>

放在自己定义的package下如:

<package name="purchases" extends="base-action" namespace="/purchases">

<result-types>
            <result-type name="json" class="org.apache.struts2.json.JSONResult"/>
        </result-types>
        <interceptors>
            <interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
        </interceptors>

<action name="addPurchasesInfo" class="com.wisdom.lxgz.purchases.action.PurchasesAction"
             method="addPurchasesInfo">
        <interceptor-ref name="ebStackWithTokenAndValidation" />
        <interceptor-ref name="chain" />
        <result type="json"></result>
        <result name="input">/jsp/purchases/initPurchasesInfo.jsp</result>
        <result name="invalid.token" type="chain">purchasesList</result>
       <exception-mapping result="success" exception="java.lang.Exception" />
    </action>

</package>

启动程序时报错:java.lang.ClassNotFoundException: org.apache.struts2.json.JSONResult.

我把struts2-json-plugin-2.2.3.jar解压后发现是有org.apache.struts2.json.JSONResult,但当解压jsonplugin-0.32.jar后发现JSONResult这个class是在com.googlecode.jsonplugin.JSONResult下,所以上面的路径改成com.googlecode.jsonplugin.JSONResult。

改好后启动没有报错,但当action向前台传值时报错:

java.lang.IllegalAccessException: Class com.googlecode.jsonplugin.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers "public"
 at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
 at java.lang.reflect.Method.invoke(Method.java:588)
 at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:224)
 …………

网上有人说是因为有类型不能序列化,所以爆出此错,网上说的四个解决方法:

1.在get Service方法上面加

@JSON(serialize = false)

例如:

@JSON(serialize = false)
     public SuperviseService getSuperviseService() {
         return safetySuperviseService;
     }
    2、修改JSONWriter 
    3、增加transient 
    4、去掉get方法

我按照方法1,在action类中把service对象的get()方法上加上@JSON(serialize=false)后,果然不报错了,并且在jsp上可以得到值了。

struts2.0整合json的更多相关文章

  1. struts2整合json要注意的问题

    昨天struts2整合json,一直出错: There is no Action mapped for namespace / and action name ... HTTP Status 404 ...

  2. Struts2.0笔记二

    Mvc与servlet 1.1   Servlet的优点 1.  是mvc的基础,其他的框架比如struts1,struts2,webwork都是从servlet基础上发展过来的.所以掌握servle ...

  3. struts2+hibernate整合开发步骤

    百度的各种代码,步骤,自己整合了一下 1,创建数据库 常用mysql   creat table..... 2,在WebContent下的bin中添加相应的包 http://pan.baidu.com ...

  4. (转)struts2.0配置文件、常量配置详解

    一.配置: 在struts2中配置常量的方式有三种: 在struts.xml文件中配置 在web.xml文件中配置 在sturts.propreties文件中配置 1.之所以使用struts.prop ...

  5. struts2中的json

    这里放一个转载的struts2中json的详细应用和范例, http://yshjava.iteye.com/blog/1333104,这是个人在网上看到的很用心也很详细的一份关于struts2中js ...

  6. 玩转spring MVC(八)----spring MVC整合json

    这篇文章在前边项目的基础上来整合json,最新项目资料见:http://download.csdn.net/detail/u012116457/8436187 首先需要的jar包:jackson-co ...

  7. 项目ITP(六) spring4.0 整合 Quartz 实现动态任务调度

    前言 系列文章:[传送门] 项目需求: http://www.cnblogs.com/Alandre/p/3733249.html 上一博客写的是基本调度,后来这只能用于,像每天定个时间 进行数据库备 ...

  8. 项目ITP(五) spring4.0 整合 Quartz 实现任务调度

    前言 系列文章:[传送门] 项目需求: 二维码推送到一体机上,给学生签到扫描用.然后需要的是 上课前20分钟 ,幸好在帮带我的学长做 p2p 的时候,接触过.自然 quartz 是首选.所以我就配置了 ...

  9. [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口(转)

    转自:[CXF REST标准实战系列] 二.Spring4.0 整合 CXF3.0,实现测试接口 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现W ...

随机推荐

  1. 【AngularJS】—— 5 表单

    这部分,我们写一个表单程序,使用angularjs的检测并完成表单属性的获取与拷贝. 在AngularJS中,也支持html5中多种控件的自动检测,如:text.number.url.email.ra ...

  2. lustre文件系统部署流程

    # 1 准备工作### 1.1 添加以太网址添加以太网地址,使得gio017可以访问到需要安装的节点.修改gio017上的/etc/hosts,将需要批量操作的节点名以如下方式添加.```[gio01 ...

  3. Apache服务器httpd.exe进程占用cpu超过50%的解决方法

    httpd.exe进程占用cpu超过50%,关闭掉Apache服务,cpu应用率立刻下降到0.  重新启动Apache又出现占用cpu高的情况.  原因是:httpd.exe和防火墙配置有冲突. 解决 ...

  4. 安装wampserver 2.5的时候出现丢失MSVCR100.dll的解决办法。

    转载地址:http://www.mafutian.net/127.html

  5. linux查找某一进程并杀死

    1. 查找redis进程 ps  -ef|grep   redis-server 2.打印第二个参数,因为上面第二列是进程号 3.这两个进程号有一个是grep进程号,所以要去掉,反选 grep ps ...

  6. java 自定义标签 传值

    <?xml version="1.0" encoding="UTF-8" ?>   <taglib xmlns="http://ja ...

  7. [Asp.net MVC]Asp.net MVC5系列——从控制器访问模型中的数据

    目录 概述 从控制器访问模型中的数据 强类型模型与@model关键字 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net M ...

  8. 在framework中打包xib

    废话不多说,直接上图 1.Copy Bundle Resources 中加入相关xib 2.这里是重点,调用的时候不能直接写 [[NSBundle mainBundle] loadNibNamed:@ ...

  9. Android权限 uses-permission

    Manifest.permission 官方API说明: http://developer.android.com/reference/android/Manifest.permission.html ...

  10. 百度地图api 常用demo

    功能一:获取map地图窗口的可视区域: var map = new BMap.Map("allmap");            // 创建Map实例 map.centerAndZ ...