使用UrlRewriteFilter如何在Tomcat crossContext的情况下上传文件

来源:互联网 发布:怎么登录ebsco数据库 编辑:程序博客网 时间:2024/06/08 05:23

正常情况下,使用UrlRewriteFilter是可以转发文件上传的请求的,Content-Type是mutlipart/form-data

但发现当想在同一个Tomcat的两个webapp之间转发请求时,即使crossContext设为true,一般的get或post请求可以正常转发,但文件上传的请求却无法正确把参数传递过去。

感觉像是tomcat在crossContext的情况下没有把请求当作multipart类型来处理,所以转发到的context无法获取到参数。

今天看tomcat的文档发现Context还有allowCasualMultipartParsing这样一个配置:

allowCasualMultipartParsing

Set to true if Tomcat should automatically parse multipart/form-data request bodies when HttpServletRequest.getPart* or HttpServletRequest.getParameter* is called, even when the target servlet isn't marked with the @MultipartConfig annotation (See Servlet Specification 3.0, Section 3.2 for details). Note that any setting other than false causes Tomcat to behave in a way that is not technically spec-compliant. The default isfalse

把这个参数设成true,再尝试一下crossContext下的文件上传请求的转发,果然好使了。

1 0