如果不是文件类型请求,我们使用request.getParameter("");方法是可以获取到参数内容的,如果是文件类型的请求即请求的头部信息为“multipart/form-data”,时,需要如下处理:
HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; String contentType = req.getContentType(); if (contentType != null && contentType.contains("multipart/form-data")) { MultipartResolver resolver = new CommonsMultipartResolver(request.getSession().getServletContext()); MultipartHttpServletRequest multipartRequest = resolver.resolveMultipart(request); // 将转化后的 request 放入过滤链中 request = multipartRequest; }
通过spring的轮子,实现request的转换,然后使用request.getParameter("");
发现参数获取正常。
原文地址:https://www.cnblogs.com/fengwenzhee/p/9804628.html
时间: 2024-11-05 16:30:48