本文主要是介绍使用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>
这篇关于使用jspSmartUpload.jar实现文件下载的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!