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

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

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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容