zoukankan      html  css  js  c++  java
  • 【报错问题】java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode

    情景:AOP获取请求参数,并转成JSON字符串时抛出

    原因

    ServletRequest,ServletResponse,MultipartFile不能被序列化,需要排除之后再做序列化。

    示例: 

    Object[] args = joinPoint.getArgs();
    Object[] arguments  = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
      if (args[i] instanceof ServletRequest || args[i] instanceof ServletResponse || args[i] instanceof MultipartFile) {
                    //ServletRequest不能序列化,从入参里排除,否则报异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
                    //ServletResponse不能序列化 从入参里排除,否则报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
                    continue;
      }
       arguments[i] = args[i];
    }
    paramter = JSONObject.toJSONString(arguments);
  • 相关阅读:
    图片处理中的Dithering技术
    网络I/O模型
    并发编程(二)
    并发编程(一)
    socket编程(二)
    socket编程(一)
    异常处理
    软件开发规范
    面向对象进阶
    多态与封装
  • 原文地址:https://www.cnblogs.com/stxyg/p/14964788.html
Copyright © 2011-2022 走看看