2

我收到以下错误: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 对象冲突。

4

1 回答 1

5

我假设您使用的是 Struts 的 2.x 版本,我遇到了同样的问题并发现了 Struts 的一个现有错误 -在此处解释

实际上,任何是 RequestAware 或 SessionAware 的操作都会自动绑定会话和请求。我从行动中删除了我的请求获取者,事情开始正常工作。

于 2012-11-21T15:12:11.550 回答