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

正常情况下,使用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下的文件上传请求的转发,果然好使了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值