当前位置: 代码迷 >> Java Web开发 >> 各位大神!struts2文件上载 360浏览器报错 !
  详细解决方案

各位大神!struts2文件上载 360浏览器报错 !

热度:120   发布时间:2016-04-16 23:55:24.0
求助各位大神!struts2文件下载 360浏览器报错 求助!!!!
本帖最后由 kk945600 于 2013-01-06 17:25:14 编辑
struts2文件上传、下载的功能,上传没有问题,但是360浏览器下载已经上传文件的时候,后台抛出异常不能下载!!这要怎么解决!!!
360中很小的文件能下载,但后台有异常
360中大一些的文件就不能下载了,

360浏览器下载时后台抛的异常:(不知道为什么 文件名后面少了一个字符)

在ie8中什么问题都没有





代码如下:

文件下载jsp页面

<form action="downloadFile.action" method="post" target="_parent">
<input type="text" name="fileName" value="<s:property value ="fileFileName" />"/>
<input type="submit" value="下载此文件"/>
</form>


struts配置文件action:

<action name="downloadFile" class="com.test.filedownload.DownloadAction2" method="downLoadFile">
<result name="success" type="stream">
        <param name="contentType">application/octet-stream;charset=ISO8859-1</param>
        <param name="inputName">inputStream</param>
        <param name="contentDisposition">
            attachment;filename="${fileName}"
        </param>
        <param name="bufferSize">2048</param>
    </result>
     <result name="input">/fileDownloadFail.jsp</result>
</action>


下载文件Action

package com.test.filedownload;
import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DownloadAction2 extends ActionSupport
{
  private String fileName;

    public String downLoadFile() throws Exception {
     return "success";
    }

    public InputStream getInputStream() throws Exception {
     String realPath = "/upload/"+fileName;
     System.out.println(realPath);

// ServletActionContext.getResponse().setHeader(
// "Content-Disposition",
// "attachment; filename="
// + java.net.URLEncoder
// .encode(this.fileName, "utf-8"));
    
    this.fileName =  java.net.URLEncoder.encode(this.fileName, "utf-8");
    
     return ServletActionContext.getServletContext().getResourceAsStream(realPath); 
    }

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}
}


360浏览器下载时后台抛的异常:(不知道为什么 文件名后面少了一个字符)

fileFileName: Visual+C+++6.0(支持win7).zip
/upload/Visual+C+++6.0(支持win7).zip
/upload/Visual+C+++6.0(支持win7).zi
2013-1-6 17:23:19 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
严重: Exception occurred during processing request: null
ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:388)
  相关解决方案