用smartupload吧,可用servlet或jsp文件实现,这是我的文件下载servletimport javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import com.jspsmart.upload.*;public class FileDownload extends HttpServlet
{
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException
{
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ try
{
response.setContentType(CONTENT_TYPE);
String content_type = "application/octet-stream";//也可自己添加判断文件格式来选择contentType
String path = getServletContext().getInitParameter(
"UPLOADPATH"); //你可随意指定本地磁盘路径
SmartUpload mySmartUpload = new SmartUpload();
String file_name=path + request.getParameter("filename"); file_name = new String(file_name.getBytes("ISO8859-1"),"GBK");
mySmartUpload.initialize(getServletConfig(), request, response); //设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
//doc时,浏览器将自动用word打开它。扩展名为pdf时,
//浏览器将用acrobat打开。
//mySmartUpload.setContentDisposition(null);
//mySmartUpload.downloadFile(file_name); mySmartUpload.downloadFile(file_name, content_type); }
catch (Exception ex)
{
ex.printStackTrace();
}
}
//Clean up resources
public void destroy()
{
}
}在jsp页面只需传递filename
import javax.servlet.http.*;
import java.io.*;
import java.util.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import com.jspsmart.upload.*;public class FileDownload extends HttpServlet
{
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException
{
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ try
{
response.setContentType(CONTENT_TYPE);
String content_type = "application/octet-stream";//也可自己添加判断文件格式来选择contentType
String path = getServletContext().getInitParameter(
"UPLOADPATH"); //你可随意指定本地磁盘路径
SmartUpload mySmartUpload = new SmartUpload();
String file_name=path + request.getParameter("filename"); file_name = new String(file_name.getBytes("ISO8859-1"),"GBK");
mySmartUpload.initialize(getServletConfig(), request, response); //设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
//doc时,浏览器将自动用word打开它。扩展名为pdf时,
//浏览器将用acrobat打开。
//mySmartUpload.setContentDisposition(null);
//mySmartUpload.downloadFile(file_name); mySmartUpload.downloadFile(file_name, content_type); }
catch (Exception ex)
{
ex.printStackTrace();
}
}
//Clean up resources
public void destroy()
{
}
}在jsp页面只需传递filename
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货