小弟用struts2文件下载的程序A,正常情况下,没有问题。
但是如果程序A的数据转换并下载正在运行期间,后台定时器Timer(布署的另一个程序B)有启动并运行,则程序A在进行文件下载getInputStream()完成后,页面还一直处于等待状态,没有跳转或获得文件. 程序A:
Class A{
  A.generateFile();
  A.download();
  A.getInputStream();
}struts.xml:<action name="download" class="com.FileDownloadAction">
<result name="success" type="stream">
<param name="contentType">text/plain</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">
attachment;filename="${filename}"
</param>
<param name="bufferSize">4096</param>
</result>
</action>

解决方案 »

  1.   

    Timer在哪里写着呢,和getInputStream有关系吗?
      

  2.   

    程序B的Timer启动后,里面有一个和InputStream有关,但好像和程序A文件下载关系不大,贴出来看.InputStream input = Thread.currentThread().getContextClassLoader().
    getResourceAsStream("Project.properties");
    prop.load(input);
    input.close();
    signal = prop.getProperty("TIMER");
    Server = prop.getProperty("SERVER");
      

  3.   

    input.close();
    是不是close()的太早了
      

  4.   


    这个close()关掉的是程序B里Timer里面的InputStream啊. 和程序A里的InputStream不同吧. 而且程序A里的InputStream也是新建的:public InputStream getInputStream() throws Exception { 
    String filePath = ServletActionContext.getServletContex().getRealPath("file")+ "/"+ downloadFileName;
    InputStream aFile = new java.io.FileInputStream(filePath);
    File file = new File(filePath);
    file.deleteOnExit();
    return aFile;

      

  5.   

    input.close();
    signal = prop.getProperty("TIMER");
    Server = prop.getProperty("SERVER");
    变成signal = prop.getProperty("TIMER");
    Server = prop.getProperty("SERVER");
    input.close();试试
      

  6.   

    Weblogic报错:<2011-9-9 下午12时50分13秒 CST> <Error> <HTTP> <BEA-101017> <[weblogic.servlet.i
    nternal.WebAppServletContext@1a376f3 - appName: 'SIR', name: 'SIR', context-path
    : '/SIR'] Root cause of ServletException.
    java.net.SocketException: socket write error: Connection reset by peer.
            at jrockit.net.SocketNativeIO.socketWrite(Ljava.io.FileDescriptor;[BII)V
    (Unknown Source)
            at java.net.SocketOutputStream.socketWrite0(Ljava.io.FileDescriptor;[BII
    )V(SocketOutputStream.java:???)
            at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
            at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
            at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.
    java:525)
            Truncated. see log file for complete stacktrace
    >
      

  7.   

    Connection reset by peer.
    链接出错了