Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java/Spring MaxUploadSizeExceedeException post参数_Java_Spring_Validation_Exception - Fatal编程技术网

Java/Spring MaxUploadSizeExceedeException post参数

Java/Spring MaxUploadSizeExceedeException post参数,java,spring,validation,exception,Java,Spring,Validation,Exception,我有一个表单,有三个文本字段和一个文件上传字段。 当我到达MaxUploadSizeExceedeException异常时,我可以使用实现HandlerExceptionResolver的类来处理。 我有自己的自定义处理程序类 resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception){ ... } 我的问题

我有一个表单,有三个文本字段和一个文件上传字段。 当我到达MaxUploadSizeExceedeException异常时,我可以使用实现HandlerExceptionResolver的类来处理。 我有自己的自定义处理程序类

resolveException(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception exception){ ... }
我的问题是,我需要一种方法将一些变量传递给异常处理程序(表单中其他字段的值),以便返回包含这些变量的ModelAndView。我不想重定向到错误页面,我想返回我的表单,而不丢失插入的值

我还有一个“验证器”,可以验证其他字段,它可以工作,但我不知道如何将它与MaxUploadSizeExceedeException异常集成

我的控制器实现HandlerExceptionResolver

@Override
public ModelAndView resolveException(HttpServletRequest request,
        HttpServletResponse response, Object handler, Exception exception)
{        
    Map<String, Object> model = new HashMap<String, Object>();

    if (exception instanceof MaxUploadSizeExceededException)
    {
        // this is empty!
        Map<String,String[]> paramMap = request.getParameterMap();

        // model.put("ticketForm", new TicketForm());
        // ticketForm.setId();

        model.put("err", exception.getMessage());
        return new ModelAndView(inserisciticket", model);
    } else
    {
        model.put("err", "Unexpected error: " + exception.getMessage());
        return new ModelAndView("error", model);
    }
}
你能帮我吗

-------------编辑2--------------------

我尝试了建议的方法

但在句柄和过滤器中,我也无法读取表单参数(post数据)。 我该怎么办


谢谢。

以下更改解决了我的应用程序中的文件上载大小问题(MaxUploadSizeExceedeException)。 在“application.yml”中执行以下更改以修复此问题。设置-1表示允许无限大小

春天: servlet: 多部分: 最大文件大小:-1

春天: servlet: 多部分:
最大请求大小:-1

以下更改解决了我的应用程序中的文件上载大小问题(MaxUploadSizeExceedeException)。 在“application.yml”中执行以下更改以修复此问题。设置-1表示允许无限大小

春天: servlet: 多部分: 最大文件大小:-1

春天: servlet: 多部分:
最大请求大小:-1

为什么不想从
HttpServlerRequest
获取参数?我尝试过,但什么也看不到。使用request.getParameterMap()我得到一个空映射。请添加您尝试过的代码。我已将代码向下发布。请编辑您的问题并将其添加到那里。为什么不想从
HttpServlerRequest
获取参数?我尝试过,但什么也看不到。使用request.getParameterMap()我得到一个空映射。请添加您尝试过的代码。我将代码向下发布。请编辑您的问题并将其添加到那里。
@RequestMapping(value = "/inseriscinuovoticket", method = RequestMethod.POST)
@ResponseBody
public String inseriscinuovoticket(
        @RequestParam(value = "idArgomento", required = true, defaultValue = "") String idArgomento,
        @RequestParam(value = "oggetto", required = true, defaultValue = "") String oggetto,
        @RequestParam(value = "descrizione", required = true, defaultValue = "") String descrizione,
        @RequestParam(value = "fileuploaded", required = false) MultipartFile fileuploaded,
        @ModelAttribute("ticket") TicketForm ticketForm, BindingResult result, Model model, HttpServletRequest request,
        Locale locale) throws IOException  { .... }
public class MultipartExceptionHandler extends OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest request,
        HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {
    try {
        filterChain.doFilter(request, response);
    } catch (MaxUploadSizeExceededException e) {
        handle(request, response, e);
    } catch (ServletException e) {
        if(e.getRootCause() instanceof MaxUploadSizeExceededException) {
            handle(request, response, (MaxUploadSizeExceededException) e.getRootCause());
        } else {
            throw e;
        }
    }
}

private void handle(HttpServletRequest request,
        HttpServletResponse response, MaxUploadSizeExceededException e) throws ServletException, IOException {

    // null
    TicketForm t = (TicketForm)request.getAttribute("ticket");
    // null
    String idArgomento = (String)request.getAttribute("idArgomento");

    response.sendRedirect("inserisciticket");
  }
}