Private String dowmLoadFile (String filename, HttpServletResponse response) {
Response. AddHeader (" the content-type ", "application/octet - stream");
OutputStream OS=null;
Enclosing the logger. The error ("====================need to download the file name: "+ filename);
String path=ftpConfig. OptString (" SFTP. Path ");
String curPath=(String) UniFtpUtil. CurFilePath. The get ();
if (! StringUtil. IsEmpty (curPath)) {
Path=curPath + "/"
UniFtpUtil. CurFilePath. Set (" ");
}
ChannelSftp channel=null;
Try {
OS=response. GetOutputStream ();
The channel=getChannel ();
The Vector ls=channel. The ls (path);
Enclosing the logger. The error ("====================server of the communist party of China "+ ls. The size () +" file ");
If ((ls!=null) & amp; & (ls. The size () & gt; {0))
String filenamei="";
for (int i=0; iChannelSftp. LsEntry entry=(ChannelSftp. LsEntry) ls. Get (I);
Filenamei=entry. GetFilename ();
Enclosing the logger. The error ("====================server first "+ I +" file file name: "+ filenamei);
{if (filenamei. The contains (filename))
Filename=filenamei;
String headName=filename. The substring (0, filename. The lastIndexOf (". "));
String tailName=filename. The substring (filename. LastIndexOf (". "));
response.addHeader("Content-Disposition", "attachment; Filename="+ new String (headName getBytes (" GBK"), "ISO - 8859-1) + tailName);
Enclosing the logger. The error ("====================begin to download file: "+ + filename path);
Channel. The get (path + filename, OS, null);
Close (channel);
Return the filename.
}
}
Enclosing the logger. The error ("====================no matching files in the server ");
} else {
Enclosing the logger. The error ("====================file does not exist the====================");
Throw new RuntimeException (download "failure");
}
{} the catch (Exception ex)
Ex. PrintStackTrace ();
This. The logger. The error (" download downFile method error ");
Throw new RuntimeException (download "failure");
} the finally {
Try {
os.close();
Close (channel);
} the catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
An error log
CodePudding user response:
There are big?CodePudding user response:
From the point of this warning, meaning is clear, response, and submit to the client, so can't set the Header parameter,But from the point of your code and log, is a bit odd,
According to your log to see, first print your post code line 4,
Then the next log is code 41 directly, 41 in the catch, and also is an exception occurs, that is to say must say one line of code that executes on the affirmation in the try, and there is no print any logs, then from the point of the code, line 15 to perform the most, because the line 16 print log, but not the console, therefore, should be the following three lines of an error:
OS=response. GetOutputStream ();
The channel=getChannel ();
The Vector ls=channel. The ls (path);
The key is the OS, and then finally closed, also is the end of the response, the whole process is not set any header ah, is behind the rest of set,
Or say this log has a problem?
CodePudding user response: