struts框架下下载EXCEL文件,怎样控制在选择直接打开后,再通过IE的保存按钮保存时,默认的文件名是所传参数的名字? struts框架下下载EXCEL文件,怎样控制在选择直接打开后,再通过IE的保存按钮保存时,默认的文件名是所传参数的名字?? 打开EXCEL文件所用的URL是: http://IP:port/xxxxxx/xxxxxx.do?FName=00001.xls 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 哪位高手帮帮忙,急急急...我现在弹出来的保存对话框中的默认要保存的文件名为"xxxxxx.do". 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,你也可以用这个方法做 谢谢楼上, 可能是我没把问题描述清楚, 我现在遇到的情况是, 点一个下载link后可以弹出选择"打开" 或 "保存"的对话框.并且点"保存"的话默认的保存文件名已经如上控制了. 问题出在选择"打开"时,EXCEL文件在IE里打开了, 这时候想用IE的"文件/保存" 来保存, 弹出的对话框中默认保存名就变成"xxxxxx.do"了.(xxxxx是struts中对应下载处里的action)请帮帮忙, 急... 那个点"文件/保存" 来保存时的文件名其实是网页上的title里的内容,也就是最上面状态栏里的内容,你可以试一下, 楼上的意思是通过程序改变状态栏中的文字? 可以具体一些吗? 我怎样才能在点打开时就改变即将弹出的IE的title?谢谢! 你试一下这样<body> <jsp:forward page="http://IP:port/xxxxxx/xxxxxx.do?FName=00001.xls" /></body>会出现什么情况 Hibernate:关于一对多 我的理解正确吗 flex上传文件问题 jsp 往数据库sql2005中插入数据时出现乱码 两个问题 怎么用JSP实现用户名和密码的问题 求套JSP代码阅读 现在有哪些好的新闻系统?开源的更好 Bean的应该放在什么地方? 大家来看看这个JSP项目如何做? JSP联数据库如何分页显示 用SQL语句 求助:Cannot find ActionMappings or ActionFormBeans collection 关于<html:select>的问题
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,你也可以用这个方法做
请帮帮忙, 急...
<body>
<jsp:forward page="http://IP:port/xxxxxx/xxxxxx.do?FName=00001.xls" />
</body>
会出现什么情况