使用SmartUpload下载时出现的问题(高分)
在jsp页面调用SmartUpload下载我用jxl生成的excel文件时,会出现下载的是我调用SmartUpload的那个jsp页面,请问怎么解决?
[解决办法]
response.setContentType( "APPLICATION/OCTET-STREAM ");
response.setHeader( "Content-Disposition ",
"attachment; filename=\ " " + filename + "\ " ");
可能跟这两个函数有关系吧,也有可能是你要下载的文件不存在.明天给你看看,我以前也遇到同样的问题,当时忘了怎么解决的了,明天去看看
[解决办法]
呵呵,其实下载的还是你那个EXECL文件,只是下载的默认文件名变成了当前的网页的名字,不信你可以把这个文件下载下来,再用EXECL打开看看
我昨天刚刚碰到这个问题
我这个可以用的,不过没有调用组件
<%@ page contentType= "text/html; charset=gb2312 " %> <%@ page import= "java.io.* " %> <%
String fileName = "kkk.txt ";
InputStream inStream=new FileInputStream(getServletContext().getRealPath( "/ ")+ "kk.txt ");
response.reset();
response.setContentType( "bin ");
response.addHeader( "Content-Disposition ", "attachment; filename= " + fileName);
byte[] b = new byte[100];
int len;
while((len=inStream.read(b)) > 0)
response.getOutputStream().write(b,0,len);
inStream.close();
%>
下载网站根目录下的kk.txt文件,下载文件名为kkk.txt
[解决办法]
我一般写成sevelet这样比较好,
public class up_downloadSevelet extends HttpServlet {
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
final public ServletConfig getServletConfig() {
return config;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String filename=request.getParameter( "filename ");//需要处理一下文件路径
response.addHeader( "Content-Disposition ", "attachment;filename= "+filename);
//SmartUpload su=new SmartUpload(getConfig().getServletContext(),request,response);
SmartUpload mySmartUpload=new SmartUpload();
try
{
mySmartUpload.initialize(config,request,response);
mySmartUpload.setContentDisposition(null);
mySmartUpload.downloadFile( "d:/ "+filename);
}
catch(Exception e)
{}
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
}
只要传回一个现在文件的文件名即可