struts框架下下载EXCEL文件,怎样控制在选择直接打开后,再通过IE的保存按钮保存时,默认的文件名是所传参数的名字?
struts框架下下载EXCEL文件,怎样控制在选择直接打开后,再通过IE的保存按钮保存时,默认的文件名是所传参数的名字??
打开EXCEL文件所用的URL是: http://IP:port/xxxxxx/xxxxxx.do?FName=00001.xls
------解决方案--------------------public void downloadFile(String sourceFilePathName, String contentType, String destFileName, int blockSize)
throws SmartUploadException,
IOException,
ServletException {
if(sourceFilePathName == null)
throw new
IllegalArgumentException(String.valueOf((new StringBuffer( "File ' ")).append(sourceFilePathName).append( " ' not found (1040). ")));
if(sourceFilePathName.equals( " "))
throw new IllegalArgumentException(String.valueOf((new StringBuffer( "File ' ")).append(sourceFilePathName).append( " ' not found (1040). ")));
if(!isVirtual(sourceFilePathName) && m_denyPhysicalPath)
throw new
SecurityException( "Physical path is denied (1035). ");
if(isVirtual(sourceFilePathName))
sourceFilePathName = m_application.getRealPath(sourceFilePathName);
File file = new File(sourceFilePathName);
FileInputStream fileIn = new FileInputStream(file);
long fileLen = file.length();
int readBytes = 0;
int totalRead = 0;
byte b[] = new byte[blockSize];
if(contentType == null)
m_response.setContentType( "application/x-msdownload ");
else
if(contentType.length() == 0)
m_response.setContentType( "application/x-msdownload ");
else
m_response.setContentType(contentType);
m_response.setContentLength((int)fileLen);
m_contentDisposition = m_contentDisposition != null ? m_contentDisposition : "attachment; ";
if(destFileName == null)
m_response.setHeader( "Content-Disposition ", String.valueOf((new StringBuffer(String.valueOf(m_contentDisposition))).append( " filename= ").append(getFileName(sourceFilePathName))));
else
if(destFileName.length() == 0)
m_response.setHeader( "Content-Disposition ", m_contentDisposition);
else
m_response.setHeader( "Content-Disposition ", String.valueOf((new StringBuffer(String.valueOf(m_contentDisposition))).append( " filename= ").append(destFileName)));
while((long)totalRead < fileLen)
{
readBytes = fileIn.read(b, 0, blockSize);
totalRead += readBytes;
m_response.getOutputStream().write(b, 0, readBytes);
}
fileIn.close();
}
这是JSPsmartUpload里下载的方法,其中m_response.setHeader( "Content-Disposition ", String.valueOf((new StringBuffer(String.valueOf(m_contentDisposition))).append( " filename= ").append(destFileName)));这句就是把下载对话框里的文件名改为参数destFileName,你也可以用这个方法做