点滴记录,是前进的脚步 2018-09-09 11:41 采纳率: 16.7%
浏览 2739
已结题

在过滤器里打印日志报如下错误(大概意思是请求不是同步的)怎么回事?

com.alibaba.fastjson.JSONException: toJSON error
com.alibaba.fastjson.JSON.toJSON(JSON.java:987)
com.alibaba.fastjson.JSON.toJSON(JSON.java:888)
。。。。。。
root cause

java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
org.apache.catalina.connector.Request.getAsyncContext(Request.java:1695)
org.apache.catalina.connector.RequestFacade.getAsyncContext(RequestFacade.java:1055)

我写的代码如下:
public class TestFilter implements Filter {
static final Logger logger = LoggerFactory.getLogger(TestFilter.class);
public void init(FilterConfig filterConfig) throws ServletException {
}

//新建一个装饰者模式的request对象,以便对request对象的参数进行更改/过滤
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    logger.info("请求为:{}",JSON.toJSON(request));
    chain.doFilter(request, response);//对request和response进行过滤
}


public void destroy() {

}

}

  • 写回答

4条回答 默认 最新

  • devmiao 2018-09-09 15:44
    关注
    评论

报告相同问题?