请教各位大虾:为什么struts2上传得到的都是.tmp的文件?
望指导,谢谢!

解决方案 »

  1.   

    //jsp文件
    <s:form action="loginInfo_uploadFile" enctype="multipart/form-data"> 
        <table>
        <tr>
              <td height="40">文件地址:</td>
              <td bgcolor="#FFFFFF"><s:file name="upload"/></td>
            </tr>
            <tr>
             
              <td><s:submit value=" 添加文件 "/></td>
            </tr>
            </table>
        </s:form>//Action
    private File upload;
    public void setUpload(File upload) {
    this.upload = upload;
    }
    public String uploadFile(){
    String address = System.currentTimeMillis()
    + upload.getName().substring(
    upload.getName().lastIndexOf("."));
    File imageFile = new File(ServletActionContext.getServletContext()
    .getRealPath("/pic")
    + "/" + address);
    copy(upload, imageFile);
    return SUCCESS;

    }private static void copy(File src, File dst) {
    try {
    InputStream in = null;
    OutputStream out = null;
    try {
    in = new BufferedInputStream(new FileInputStream(src));
    out = new BufferedOutputStream(new FileOutputStream(dst));
    byte[] buffer = new byte[1024 * 10];
    while (in.read(buffer) > 0) {
    out.write(buffer);
    }
    } finally {
    if (null != in) {
    in.close();
    }
    if (null != out) {
    out.close();
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }// struts.xml
    <action name="xxx" class="xxxx" method="{1}">
        <param name="savePath">/pic</param>
                <interceptor-ref name ="fileUpload"> 
                   
                    <param name="maximumSize">1024000</param>
                </interceptor-ref> 
                <interceptor-ref name ="defaultStack"/> 
    .....
    //struts.properties
    struts.ui.theme=simple
    struts.i18n.encoding=utf-8
    struts.action.extension=htm
    struts.multipart.saveDir=d:/tmp
    struts.objectFactory = spring
      

  2.   

    .tmp是struts的临时文件,上传完成后即可得到完整的文件
    估计是上传过程中出现错误啊
      

  3.   

              <interceptor-ref name ="fileUpload"> 
                  
                    <param name="maximumSize">1024000 </param> 
                </interceptor-ref> 或许是因为这个的缘故吧 可能你上传的文件太大了 中途就断了? 猜的 我用的时候没出现过