`

Struts2、Spring中json插件出现的错误

阅读更多
action代码:
package org.lhl.hotel.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.lhl.hotel.po.Room;
import org.lhl.hotel.po.RoomType;
import org.lhl.hotel.service.RoomService;
import org.lhl.hotel.vo.Users;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class RoomAction extends ActionSupport {
private static final long serialVersionUID = 3015533791823149271L;

private RoomService roomService;
private List<Users> userList;
private Integer totalProperty;

@JSON(name="totalProperty")
public Integer getTotalProperty() {
   return totalProperty;
}

public void setTotalProperty(Integer totalProperty) {
   this.totalProperty = totalProperty;
}

@JSON(name="userList")
public List getUserList() {
   return userList;
}

public void setUserList(List<Users> userList) {
   this.userList = userList;
}

public String roomStatus() throws Exception {
 
   Integer start = new Integer(((String[])ActionContext.getContext().getParameters().get("start"))[0]);
   initList(start);
   return SUCCESS;
}

private void initList(Integer start) {
   userList = new ArrayList<Users>();
   Users user = null;
   for (int i=start; i<start+10; i++) {
    user = new Users();
    user.setUsername("username"+i);
    user.setPassword("password"+i);
    user.setSex(new Integer(1).byteValue());
    user.setAge(new Integer(20));
    user.setBirthday(new Date());
    userList.add(user);
   }
}

public RoomService getRoomService() {
   return roomService;
}

public void setRoomService(RoomService roomService) {
   this.roomService = roomService;
}
}
struts2配置文件:
<package name="demo" namespace="/" extends="json-default">
   <action name="roomStatus" class="room" method="roomStatus">
    <result type="json" />
   </action>
</package>

产生的异常:
java.sql.SQLException: Positioned Update not supported.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.getCursorName(ResultSet.java:1922)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getCursorName(NewProxyResultSet.java:545)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:224)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:321)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:225)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:157)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:123)
at com.googlecode.jsonplugin.JSONWriter.write(JSONWriter.java:91)
at com.googlecode.jsonplugin.JSONUtil.serialize(JSONUtil.java:90)
at com.googlecode.jsonplugin.JSONResult.execute(JSONResult.java:173)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

分析---------------------------------------------------------------------------------------
在我的Action中一共有3个properties,其中有个bean是roomService,而且是在spring framework中已经实例化了的,问题就出在它身上了。于是在struts-config中加入该bean的exclude,再测试,成功了!
发送action的request后,服务返回JSON数据。

解决-----------------------------------------------------------------------------------------
<package name="demo" namespace="/" extends="json-default">
   <action name="roomStatus" class="room" method="roomStatus">
    <result type="json">
     <param name="excludeProperties">
                      roomService
       </param>
      </result>
   </action>
</package>
分享到:
评论

相关推荐

    struts2_spring_json.rar_liferay struts2 json_portlet json_spring

    1. **Struts2 JSON插件**:了解如何配置Struts2的json-plugin,使得Action可以直接返回JSON结果,而无需额外的视图层处理。 2. **Spring整合Struts2**:学习如何在Spring容器中管理Struts2的Action类,以及如何通过...

    Struts2+Spring2.5+jdbc+Ext+json实例的lib包

    在"Struts2+Spring2.5+jdbc+Ext+json实例的lib包"中,可能包含了上述技术的相应库文件,如Struts2的struts2-core、spring的spring-context、jdbc驱动、Ext库文件(如ext-js和ext-core)以及用于处理JSON的json-lib或...

    Struts2与JSON

    在Struts2中,我们可以通过Action类返回一个JSON结果类型,这样Struts2会自动将Action的属性转化为JSON格式并返回给客户端。客户端通常使用JavaScript库如jQuery来接收并处理这些数据。 在描述中提到的"以JQuery...

    struts2的json插件配置详解(附demo)

    为了方便ajax调用传输数据,在struts2中加入的json插件用来做对象的序列化和反序列化,json插件的下载地址 http://code.google.com/p/jsonplugin/ 1. 下载json插件包,将jar包拷贝到WEB-INF/lib目录 注:struts2...

    struts2+spring2.5+jdbc+ext+json实例用到的lib包

    Struts2、Spring 2.5、JDBC、Ext 和 JSON 是 Java Web 开发中常见的技术栈,它们各自承担着不同的职责,共同构建了一个功能强大的应用程序。在这个实例中,我们看到的是一个集成这些技术的库文件集合。接下来,我们...

    Struts2 Spring2.5 Hiberante3.3.2 +ExtJS(Struts2-json)做的CRUD

    这个DEMO是将这些技术集成在一起,以实现数据的创建(Create)、读取(Read)、更新(Update)和删除(Delete),即CRUD操作,并且利用Struts2的JSON插件来增强与前端ExtJS的交互。 首先,Struts2作为表现层框架,...

    struts2 json传输对象文档+jar包

    在Struts2中使用JSON,首先需要在配置文件(struts.xml)中启用JSON插件,并指定哪些Action支持JSON输出。然后,在Action类中,你可以创建一个返回类型为`Map, Object&gt;`或自定义对象的方法,这个方法将被转换成JSON...

    json_struts2.rar_JSON java_SSH json Struts2_java json_json_strut

    2. **Struts2的JSON插件**:Struts2有专门的JSON插件,可以轻松地启用JSON支持。通过配置struts.xml,我们可以指定哪些Action应返回JSON响应,并定义要包含在JSON响应中的字段。 3. **jQuery的Ajax方法**:如`$....

    spring整合struts2,ibatis及其json的交互

    在Struts2中,可以通过使用Struts2的JSON插件轻松地实现JSON输出。配置struts-plugin.xml,启用JSON支持,然后在Action类中添加返回类型为"json"的结果,Struts2会自动将Java对象转换为JSON格式并返回给客户端。 在...

    struts2+json

    在Struts2中集成JSON,可以使得应用能够以JSON格式返回数据,这在开发RESTful API或者需要前端与后端进行异步交互的应用中特别有用。非注解方式意味着我们将不依赖于Struts2的注解配置,而是通过XML配置文件来定义...

    Struts2 Spring Hibernate

    在Struts2中,可以使用Struts2的JSON插件来支持JSON响应,使得前端能够快速解析数据,提高用户体验。 在实际项目中,session回收和事务处理是两个关键的方面。session回收通常涉及到会话管理,防止因为用户的长时间...

    Struts 2中启用json ajax支持

    值得注意的是,随着技术的发展,如今很多开发者可能会选择Spring Boot或React等现代框架进行开发,但了解如何在Struts 2中使用JSON和AJAX仍然是有价值的知识,尤其是对于维护旧项目或者理解Web应用基础架构时。

    struts2-json-plugin

    处理action返回结果和json互转 struts2-json-plugin-2.3.1.2.jar

    Struts2+Spring+Hibernate+Ehcache+AJAX+JQuery+Oracle 框架集成用户登录注册Demo工程

    2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。 4.在服务端分页查询功能,优点:实时性:跳页才查询。数据量小:只加载当前页的记录...

    Struts2+Spring整合所需jar包

    3. 在Struts2的配置文件中(struts.xml或struts-plugin.xml)启用Spring插件。 4. 定义Action类,通过`@Autowired`注解或`@Component`声明Spring Bean的依赖。 5. 如果使用约定优于配置,Action类可以直接按命名规则...

    struts2和spring整合包

    Struts2和Spring是两个非常著名的Java开源框架,它们在企业级应用开发中扮演着重要角色。Struts2主要用于处理MVC(Model-View-Controller)架构中的控制器部分,而Spring则是一个全面的企业级应用框架,包括依赖注入...

    spring json dwr struts2.0 hibernate整合

    在Spring和Struts2中,JSON常用于数据传输,提供快速的数据交换和页面动态更新。 整合这些框架的过程通常包括以下步骤: 1. 配置Spring:创建Spring配置文件,定义bean并管理依赖。 2. 配置Hibernate:设置数据库...

    struts+spring集成

    7. **异常处理**:Spring提供了全局异常处理机制,可以捕获并处理Struts2中抛出的异常,提供统一的错误页面或者返回JSON格式的错误信息。 8. **国际化**:Struts2和Spring都可以支持国际化,集成后可以更好地协调这...

    Struts2+spring2.5+EXT+json实例

    Struts2、Spring2.5、EXT和JSON是四个在Web开发中至关重要的技术,它们共同构建了高效、灵活和可扩展的Web应用程序。这里,我们深入探讨这四个技术及其在实际项目中的应用。 首先,Struts2是一个基于MVC(Model-...

Global site tag (gtag.js) - Google Analytics