使用jspSmartUpload.jar实现文件下载

index.jsp代码

<%@ page language="java" import="java.util.*,com.jspsmart.upload.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
    
    <title>下载页</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <form action="do_download.jsp" method="post" enctype="multipart/form-data">
    	  <a href="do_download.jsp">mi6.jpg</a>
    	  <input type="submit" name="download" value="下载">
    	  
    </form>
   
 
  </body>
</html>

do_download.jsp代码

<%@ page language="java" import="java.util.*,com.jspsmart.upload.*" pageEncoding="utf-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    
    <title>My JSP 'do_download.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    	// 新建一个SmartUpload对象
		SmartUpload su = new SmartUpload();
		// 初始化
		su.initialize(pageContext);
		// 设定contentDisposition为null以禁止浏览器自动打开文件,
		//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
		//doc时,浏览器将自动用word打开它。扩展名为pdf时,
		//浏览器将用acrobat打开。
		su.setContentDisposition(null);
		// 下载文件
	try{
		su.downloadFile("/upload/mi6.jpg");
		
	}
	catch(Exception e)
	{
		//e.printStackTrace();
	  	out.println(e.getMessage());
	}
     %>
  </body>
</html>

猜你喜欢

转载自blog.csdn.net/thinkpet/article/details/80378264