重要提示:以下问题已在 Struts 版本中得到修复
2.3.24
。从那个版本开始,不需要转义任何字符。
阅读更多:JIRA 问题 WW-4457。
我已将 Struts2 FileUpload 拦截器配置为允许 Content-Types 白名单。
这适用于与指定的 Content-Type 匹配的任何文件,但不适用于SVG
具有MIME 媒体类型image/svg+xml
的文件。
使用此配置:
@Action(value = "upload",
interceptorRefs = @InterceptorRef(
value = "defaultStack",
params = { "fileUpload.allowedTypes" , "application/pdf,"
+ "image/jpeg,"
+ "image/gif,"
+ "image/png,"
+ "image/svg+xml"
}))
并上传有效的 SVG 文件,我收到属性定义的错误消息struts.messages.error.content.type.not.allowed
:
不允许的内容类型:{0}“{1}”“{2}”{3}
{3}
用户尝试上传的 Content-Type在哪里;
然后例如:
不允许的内容类型:myFile "Sample.svg" "upload__123__456__78.tmp" image/svg+xml
这与我在白名单中定义的 Content-Type完全相同allowedTypes
。
请注意,我使用regex
模式匹配器,在 struts.xml 中使用以下常量启用:
<constant name="struts.patternMatcher" value="regex" />
为什么它不起作用,以及如何使它起作用?