本文介绍了带地图的Struts2多文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts2上传多个文件。我使用Java静态动作属性进行映射时,效果很好。但是我正在使用Map来收集所有文件。我只得到文件对象。我没有得到fileName和内容类型。

 

公共类TableListAction扩展了ActionSupport
{
private Map raja;
公共地图getRaja()
{
return raja;
}
public void setRaja(地图raja)
{
this.raja = raja;
}
public String upload()引发异常
{
System.out.println(raja);
返回成功;
}

}

我的Jsp此

 

< s:form enctype = multipart / form-data method = post action = upload>
< s:file name = raja ['column']>< / s:file>
< s:file name = raja [’column’]>< / s:file>
< s:file name = raja [’column’]>< / s:file>
< s:file name = raja [’column’]>< / s:file>
< s:submit />

在上传过程中,我在其中获取文件对象数组 raja 映射,但没有获取文件名和内容类型。



在此先感谢



请注意
Shreeram A

解决方案
 

< s:form enctype = multipart / form-data method = post action = upload>
< s:file name = raja.column>< / s:file>
< s:file name = raja.column>< / s:file>
< s:file name = raja.column>< / s:file>
< s:file name = raja.column>< / s:file>
< s:submit />


它们是使用FileName和ContentType附加名称属性。



我在这样的名称之前使用过 raja ['column'] ,因此结果是 raja ['column'] FileName
raja ['column'] ContentType



然后我修改了 raja.column 。然后它将像 raja.columnContentType raja.columnFileName

一样正确附加FileName和ContentType,现在可以正常工作了。

谢谢

Shreeram A


I am doing Multiple file upload with Struts2. It was working fine I map with java static action properties. But I am using Map to collect all the files. I am getting only the file object. I am not getting the fileName and content type.


public class TableListAction extends ActionSupport
{
    private Map raja;
    public Map getRaja()
     {
    return raja;
     }
    public void setRaja(Map raja)
     {
    this.raja = raja;
     }
     public String upload() throws Exception
     {
        System.out.println(raja);
        return SUCCESS;
    }

}

My Jsp like this


<s:form enctype="multipart/form-data" method="post" action="upload">
<s:file name="raja['column']"></s:file>
<s:file name="raja['column']"></s:file>
<s:file name="raja['column']"></s:file>
<s:file name="raja['column']"></s:file>
<s:submit/>

During uploading I am getting the file object array in that raja Map but I am not getting the fileName and contenttype.

Thanks in Advance

regardsShreeram A

解决方案

<s:form enctype="multipart/form-data" method="post" action="upload">
<s:file name="raja.column"></s:file>
<s:file name="raja.column"></s:file>
<s:file name="raja.column"></s:file>
<s:file name="raja.column"></s:file>
<s:submit/>

They are append name attribute with FileName and ContentType.

I used before name like this raja['column'], so the result raja['column']FileName andraja['column']ContentType. It wont come into the the Map.

Then i modified raja.column. Then it will append FileName and ContentType correctly like raja.columnContentType and raja.columnFileName

Its work fine now.
Thanks
Shreeram A

这篇关于带地图的Struts2多文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 05:43