- 軟件大小:53KB
- 軟件語(yǔ)言:中文
- 軟件類型:國產軟件
- 軟件(jiàn)類別:免費軟件 / 編程工具
- 更新時間:2017-07-24 15:39
- 運(yùn)行(háng)環境(jìng):WinAll, WinXP, Win7, Win8
- 軟件(jiàn)等級:
- 軟件廠商:
- 官(guān)方網站:暫(zàn)無


553KB/中文/1.5
1.88M/中文/0.0
1.13M/中文/10.0
2.65M/中文/5.0
42KB/中文/10.0
commons-fileupload.jar是maven中的實現文(wén)件上傳的控製大(dà)小的(de)組件,通過這款開源工具,讓(ràng)用戶在調用java語言時可以更加便(biàn)捷,綠色資源網(wǎng)誠意推薦!
使用(yòng)最為廣泛的Java文件上傳組件(jiàn),Struts本身采用(yòng)這個包來處(chù)理文件上傳。文檔(dàng)非(fēi)常詳細、簡單易用。
// 文件的下載
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 找到用(yòng)戶所選定的文(wén)件
String uuidname = request.getParameter(“filename”);
uuidname = new String(uuidname.getBytes(“ISO8859-1”), “utf-8”);
String realname = uuidname.substring(uuidname.indexOf(“_”)+1);
// 確定文件的保(bǎo)存位置
String savePath = getFileAddr(realname);
File f = new File(savePath + “\\” + uuidname);
//System.out.println(savePath+“<br/>”+uuidname);
if (f.exists()) {
// 設置應答的相(xiàng)應消息(xī)頭
response.setcontentType(“application/x-msdownload”);
String str = “attachment;filename=”+ java.NET.URLEncoder.encode(realname, “utf-8”);
response.setHeader(“Content-Disposition”, str);
// 創建一 個輸入流對象和指定的文件(jiàn)相關聯
FileInputStream in = new FileInputStream(f);
// 從response對象中獲(huò)取到輸出流(liú)對象
OutputStream out = response.getOutputStream();
// 從輸入流對象(xiàng)中讀數據寫入到輸出(chū)流對象中
byte[] buff = new byte[1024];
int len = 0;
while ((len = in.read(buff)) > 0) {
out.write(buff, 0, len);
}
}else{
request.setAttribute(“message”, “下載資源不(bú)存在(zài)”);
request.getRequestDispatcher(“/message.jsp”)。forward(request, response);
}
}
//根據文件名查找路徑
private String getFileAddr(String filename) {
int dir1 = filename.hashCode() & 0x0f;
int dir2 = filename.hashCode()》4 & 0x0f;
System.out.println(dir1+“====”+dir2);
String savePath = this.getServletContext()。getRealPath(“WEB-INF/upload”)
+ “\\” + dir1 + “\\” + dir2;
System.out.println(“=============”+savePath);
return savePath;
}
請描述您所遇到的錯誤,我們將盡快予以修正,謝謝(xiè)!
*必填項,請輸入內容