今天在SSH项目中遇到运用JSON插件,产生如下异常:
该异常有两种解决方法:
第一:在struts.xml文件的配置中排除不要被JSON序列化的属性,例如:
其中functionsService就是不要被JSON序列化的属性。
第二:在Action文件中去除不要被JSON序列化的属性的get()方法,例如:
这样做functionsService同样不会被JSON序列化。
说明:
带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON。
2008-11-15 12:58:21 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.sql.SQLException: Positioned Update not supported.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.getCursorName(ResultSetImpl.java:2050)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getCursorName(NewProxyResultSet.java:545)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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 zz.WebNews.util.AuthorizationInterceptor.intercept(AuthorizationInterceptor.java:62)
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 zz.WebNews.util.AuthFilter.doFilter(AuthFilter.java:62)
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(Unknown Source)
该异常有两种解决方法:
第一:在struts.xml文件的配置中排除不要被JSON序列化的属性,例如:
<action name="functions" class="getFunctionsAction" method="functions_getList">
<result type="json">
<param name="excludeProperties">functionsService</param>
</result>
</action>
其中functionsService就是不要被JSON序列化的属性。
第二:在Action文件中去除不要被JSON序列化的属性的get()方法,例如:
public IFunctionsService getFunctionsService() {
return functionsService;
}
这样做functionsService同样不会被JSON序列化。
说明:
带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON。