资源简介

JAVA 上传下载 源代码JAVA 上传下载 源代码JAVA 上传下载 源代码JAVA 上传下载 源代码JAVA 上传下载 源代码JAVA 上传下载 源代码JAVA 上传下载 源代码

资源截图

代码片段和文件信息

package com.softfz.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 


 * title:
 * 


 * 


 * Description:
 * 


 * 


 * Copyright: Copyright (c) 2006
 * 


 * 


 * Company:
 * 


 * 
 * @author not attributable
 * @version 1.0
 */

public class DownLoadServlet extends HttpServlet {
private static final 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 {

String filepath = ““;
String filename = ““;
try {
filename = request.getParameter(“filepath“);
System.out.println(filename);


 filename = this.IsoToGbk(filename);
 System.out.println(filename);
response.setContentType(this.getContentType(filename));
response.setHeader(“Content-disposition“ “attachment;filename=“
+ filename);
filepath = this.getServletContext().getRealPath(“/“);

filepath = filepath + filename;
filepath = filepath.replace(‘\\‘ ‘/‘);
System.out.println(filepath);

FileInputStream fis = new FileInputStream(filepath);
OutputStream fos = response.getOutputStream();

int bytesRead = 0;
byte[] buffer = new byte[1024];
while ((bytesRead = fis.read(buffer)) != -1) {
fos.write(buffer 0 bytesRead); // 将文件发送到客户端
}
} catch (Exception ex) {
response.setContentType(“text/html“);
// response.reset();
// 设置文件物理下载时出现的错误信息
PrintWriter out = response.getWriter();
out.println(“文件下载出现错误,请联系相关人员“);
}

}

// Process the HTTP Post request
public void doPost(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
doGet(request response);
}

// Clean up resources
public void destroy() {
}

private String IsoToGbk(String str) {
try {
if (str == null || str.equals(“null“)) {
str = ““;
} else {
str = new String(str.getBytes(“ISO-8859-1“) “GBK“);
}
} catch (Exception ex) {
ex.printStackTrace();
str = ““;
}
return str;
}

private String getContentType(String filepath) {
String fileNameTmp = filepath.toLowerCase();
String ret = ““;
if (fileNameTmp.endsWith(“txt“)) {
ret = “text/plain“;
}
if (fileNameTmp.endsWith(“gif“)) {
ret = “image/gif“;
}
if (fileNameTmp.endsWith(“jpg“)) {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        949  2008-06-06 11:20  上传下载\多文件上传\moreupload\upload\.classpath

     文件        291  2008-06-06 11:20  上传下载\多文件上传\moreupload\upload\.mymetadata

     文件        347  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\.mystrutsdata

     文件       1429  2007-03-30 00:01  上传下载\多文件上传\moreupload\upload\.project

     文件       1281  2008-06-06 14:23  上传下载\多文件上传\moreupload\upload\WebRoot\upload.jsp

     文件        484  2007-03-30 00:00  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\.struts-config.mex

     文件       8860  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\struts-bean.tld

     文件        693  2007-03-30 00:00  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\struts-config.xml

     文件      73617  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\struts-html.tld

     文件      14731  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\struts-logic.tld

     文件      71483  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\struts-nested.tld

     文件       7842  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\struts-tiles.tld

     文件        942  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\web.xml

     文件     358273  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\antlr.jar

     文件     188671  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\commons-beanutils.jar

     文件     168446  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\commons-digester.jar

     文件      22379  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\commons-fileupload.jar

     文件      38015  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\commons-logging.jar

     文件      84462  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\commons-validator.jar

     文件      65425  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\jakarta-oro.jar

     文件     543706  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\lib\struts.jar

     文件         75  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\classes\com\ggs\ApplicationResources.properties

     文件       3380  2008-06-06 11:20  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\classes\com\ggs\upload\UploadAction.class

     文件       1360  2008-06-06 11:20  上传下载\多文件上传\moreupload\upload\WebRoot\WEB-INF\classes\com\ggs\upload\UploadForm.class

     文件         39  2007-03-29 23:49  上传下载\多文件上传\moreupload\upload\WebRoot\meta-INF\MANIFEST.MF

     文件         75  2007-03-29 23:50  上传下载\多文件上传\moreupload\upload\src\com\ggs\ApplicationResources.properties

     文件       2577  2007-10-23 22:43  上传下载\多文件上传\moreupload\upload\src\com\ggs\upload\UploadAction.java

     文件       1624  2007-10-23 22:26  上传下载\多文件上传\moreupload\upload\src\com\ggs\upload\UploadForm.java

     文件       1087  2008-06-02 10:55  上传下载\仿163上传\OA\.classpath

     文件        279  2008-06-02 10:54  上传下载\仿163上传\OA\.mymetadata

............此处省略290个文件信息

评论

共有 条评论