为了获得
HttpServletRequest#getParts()在一个工作
Filter在Tomcat中,您需要设置
allowCasualMultipartParsing="true"在webapp的
<Context>元素
Webapp/meta-INF/context.xml或
Tomcat/conf/server.xml。
<Context ... allowCasualMultipartParsing="true">
因为根据Servlet3.0规范,该
HttpServletRequest#getParts()属性只能在
HttpServlet带有
@MultipartConfig注释的内使用。另请参阅
<Context>元素的文档:
allowCasualMultipartParsing设置为
trueTomcat是否应multipart/form-data在调用HttpServletRequest.getPart*或时自动解析请求主体HttpServletRequest.getParameter*,即使目标servlet没有标注@MultipartConfig注释(有关详细信息,请参见Servlet
Specification
3.0,第3.2节)。请注意,除了设置以外,任何其他设置false都会导致Tomcat的行为在技术上不符合规范。默认值为false。
与 具体问题 无关 ,以下绝对不正确:
byte[] b = new byte[(int) p.getSize()];p.getInputStream().read(b);params.put(p.getName(), new String[]{new String(b)});首先,您不遵守客户端指定的字符编码-如果有的话。其次,这对于二进制文件将失败。



