我得到以下错误:java.lang.IllegalStateException:在使用Struts2实现JSON时,已经为此请求调用了getInputStream()。 例外:
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException:
java.lang.reflect.InvocationTargetException
org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:230)
org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126)
org.apache.struts2.json.JSONWriter.write(JSONWriter.java:94)
org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:115)
org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
org.apache.struts2.json.JSONResult.execute(JSONResult.java:170)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
...........
java.lang.IllegalStateException: getInputStream() has already been called for this request
org.apache.catalina.connector.Request.getReader(Request.java:1242)
org.apache.catalina.connector.RequestFacade.getReader(RequestFacade.java:506)
javax.servlet.ServletRequestWrapper.getReader(ServletRequestWrapper.java:212)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:210)
org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126)
org.apache.struts2.json.JSONWriter.add(JSONWriter.java:355)
org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:215)
org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126)
org.apache.struts2.json.JSONWriter.write(JSONWriter.java:94)
org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:115)
org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
org.apache.struts2.json.JSONResult.execute(JSONResult.java:170)
.........
请帮我解决这个错误,因为我遇到了这个问题 我有几个问题: 我已经实现了ServletRequestAware并使用它来获取userLocale。它是否与JSONWriter对象冲突。
答案 0 :(得分:4)
我假设您使用的是Struts的2.x版本,我遇到了同样的问题并发现了Struts的一个现有错误 - explained here
实际上,RequestAware或SessionAware的任何操作都会自动绑定会话和请求。我从行动中移除了我的请求获取,事情开始正常。