Struts2 文件上传为什么会自动生成对应file的fileName和ContentType

来源:互联网 发布:mysql读写分离原理 编辑:程序博客网 时间:2024/05/17 02:07

Struts2 文件上传为什么会自动生成对应file的fileName和ContentType

根据官方文档来说,这是因为使用了FileUploadInterceptor拦截器,然后又把他们放到了Param中,所以在action中能取得到.下面是关键的代码:

...public String intercept(ActionInvocation invocation)...String contentTypeName = (new StringBuilder()).append(inputName).append("ContentType").toString();String fileNameName = (new StringBuilder()).append(inputName).append("FileName").toString();...Map params = ac.getParameters();params.put(inputName, ((Object) (acceptedFiles.toArray(new File[acceptedFiles.size()]))));params.put(contentTypeName, ((Object) (acceptedContentTypes.toArray(new String[acceptedContentTypes.size()]))));params.put(fileNameName, ((Object) (acceptedFileNames.toArray(new String[acceptedFileNames.size()]))));
1 0