您的位置:首页 > 运维架构 > Tomcat

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

2014-07-19 16:06 393 查看
正常情况下,使用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 is
false


把这个参数设成true,再尝试一下crossContext下的文件上传请求的转发,果然好使了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: