文件名不显示上载文件的名称

时间:2013-05-27 00:46:21

标签: java file-upload struts2

我有一个简单的表单来上传文件,它显示了带有tmp扩展名的文件名,但没有显示上传文件的实际名称。

JSP

    <s:form id="uploadCSV" method="POST" action="add"  enctype="multipart/form-data">
        <s:file name="csv" label="Upload File"/>
        <s:submit/>
    </s:form>

Java

    private File csv;
    private String contentType;
    private String fileName;
    private String filename;
    private String FileName;
    private String Filename;

    .....   all getter setters here .....

    System.out.println("file:" + fileName);      <<null
    System.out.println("Name >>>>" + this.csv.getName()); << upload_344f45f4f54f5f5_54r5r4000.tmp
    System.out.println("Name >>>>" + this.contentType);   << null  
    System.out.println("Name >>>>" + this.FileName);     << null
    System.out.println("Name >>>>" + this.Filename);     << null
    System.out.println("Name >>>>" + this.filename);     << null

1 个答案:

答案 0 :(得分:2)

将以下必需的成员字段添加到您的操作中。

private String csvFileName;
private String csvContentType;

我认为您现在可以轻松找出命名方案。

private File <fileInputFormName>;

private String <fileInputFormName>FileName;
private String <fileInputFormName>ContentType;