JSP文件下载
jsp下载全攻略
1、下载链接页面download.html
页面源码如下:
<!--
文件名:download.html
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>下载</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<a href="jsp/do_download.jsp">点击下载</a>
</body> ></html>
2、下载处理页面do_download.jsp
源码如下:
<%@ page contentType="text/html;charset=gb2312"
import="com.jspsmart.upload.*" %><%
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 初始化
su.initialize(pageContext);
// 设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
//doc时,浏览器将自动用word打开它。扩展名为pdf时,
//浏览器将用acrobat打开。
su.setContentDisposition(null);
// 下载文件
su.downloadFile("/upload/如何赚取我的第一桶金.doc");
%>
3、如何下载中文文件
public void downloadFile(String s, String s1, String s2, int i)
throws ServletException, IOException, SmartUploadException
{
if(s == null)
throw new IllegalArgumentException("File '" + s +"' not found (1040).");
if(s.equals(""))
throw new IllegalArgumentException("File '" + s +
"' not found (1040).");
if(!isVirtual(s) && m_denyPhysicalPath)
throw new SecurityException("Physical path is
denied (1035).");
if(isVirtual(s))
s = m_application.getRealPath(s);
java.io.File file = new java.io.File(s);
FileInputStream fileinputstream = new FileInputStream(file);
long l = file.length();
boolean flag = false;
int k = 0;
byte abyte0[] = new byte[i];
if(s1 == null)
m_response.setContentType("application/x-msdownload");
else
if(s1.length() == 0)
m_response.setContentType("application/x-msdownload");
else
m_response.setContentType(s1);
m_response.setContentLength((int)l);
m_contentDisposition = m_contentDisposition != null ?
m_contentDisposition : "attachment;";
if(s2 == null)
m_response.setHeader("Content-Disposition",
m_contentDisposition + " filename=" +
toUtf8String(getFileName(s)));
else
if(s2.length() == 0)
m_response.setHeader("Content-Disposition",
m_contentDisposition);
else
m_response.setHeader("Content-Disposition",
m_contentDisposition + " filename=" + toUtf8String(s2));
while((long)k < l)
{
int j = fileinputstream.read(abyte0, 0, i);
k += j;
m_response.getOutputStream().write(abyte0, 0, j);
}
fileinputstream.close();
}
public static String toUtf8String(String s) {
StringBuffer sb = new StringBuffer();
for (int i=0;i<s.length();i++) {
char c = s.charAt(i);
if (c >= 0 && c <= 255) {
sb.append(c);
} else {
byte[] b;
try {
b = Character.toString(c).getBytes("utf-8");
} catch (Exception ex) {
System.out.println(ex);
b = new byte[0];
}
for
JSP文件下载代码示例 暂无评价 2页 免费JSP代码文件 暂无评价0人阅读0次下载举报文档 网上书店的代码Login...
jsp实现文件上传和下载(代码及说明)_IT/计算机_专业资料。jsp实现文件上传和下载(代码及说明)特点: 1. 可以多文件上传; 2. 返回上传后的文件名; 3. form 表单...
jspSmartUpload组件使用非常简单。在jsp文件中仅需要写几行代码就可以实现文件的上传、下载。并能够全程控制上传。利用jspSmartUpload组件提供的对象及其操作方法,可以...
jsp实现文件上传和下载(代码及说明)_计算机软件及应用_IT/计算机_专业资料。特点: 1. 可以多文件上传; 2. 返回上传后的文件名; 3. form 表单中的其他参数也可...
暂无评价0人阅读0次下载举报文档 JSP上传文件代码_IT/计算机_专业资料。JSP上传文件代码UploadExample.jsp <%@ page contentType="text/html;charset=gb2312"%...
? 首选新建一个和你 jsp 项目代码的名字一摸一样, 然后将你下载的项目文件夹下面的文 件全部复制到你新建的项目文件夹下面然后在 Eclipse 里面右键点你的项目点...
jsp实现文件上传和下载 及留言板功能(代码及说明)_IT/计算机_专业资料。Jsp 实现文件上传和下载功能以及留言板功能 文件上传和下载功能特点: 特点 1. 可以多文件上...
暂无评价0人阅读0次下载举报文档 登录的JSP源代码_计算机软件及应用_IT/计算机_专业资料。一个网站的登录源代码Login.jsp <%@ page language="java" pageEnco...
jsp技术的文件上传代码_财务管理_经管营销_专业资料 暂无评价0人阅读0次下载举报文档 jsp技术的文件上传代码_财务管理_经管营销_专业资料。简要介绍资料的主要...
热门文档