好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Apache FileUpload的兩種上傳方式介紹及應(yīng)用

Apache FileUpload的兩種上傳方式介紹及應(yīng)用

熱門標(biāo)簽:智能電話機(jī)器人銷售話術(shù) 四川正規(guī)外呼系統(tǒng)軟件 外呼直播語音系統(tǒng) 山東ai外呼電銷機(jī)器人好用嗎 湖北地圖標(biāo)注公司 甘肅銷售電銷機(jī)器人公司 地圖標(biāo)注專業(yè)和非專業(yè) 福建電銷貓機(jī)器人收費(fèi) 汝南縣地圖標(biāo)注app
環(huán)境
tomcat5.6
commmons-fileupload-1.3.jar
commmons-io-2.4.jar
JSP
編碼:UTF-8
臨時文件夾:fileupload/tmp相對于網(wǎng)站根目錄
上傳文件保存位置:fileupload
Traditional API上傳方式
//fileload01.htm
復(fù)制代碼 代碼如下:

meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
html>
body>
form method="POST" enctype="multipart/form-data" action="traditionalapi.jsp">
File to upload: input type="file" name="file" size="40">br/>
input type="submit" value="Press"> to upload the file!
/form>
/body>
/html>

//traditionalapi.jsp
復(fù)制代碼 代碼如下:

%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java"%>
%@page import="java.io.File"%>
%@page import="java.util.List"%>
%@page import="org.apache.commons.fileupload.*"%>
%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
%
request.setCharacterEncoding("UTF-8");
// file less than 10kb will be store in memory, otherwise in file system.
final int threshold = 10240;
final File tmpDir = new File(getServletContext().getRealPath("/") + "fileupload" + File.separator + "tmp");
final int maxRequestSize = 1024 * 1024 * 4; // 4MB
// Check that we have a file upload request
if(ServletFileUpload.isMultipartContent(request))
{
// Create a factory for disk-based file items.
FileItemFactory factory = new DiskFileItemFactory(threshold, tmpDir);

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Set overall request size constraint.
upload.setSizeMax(maxRequestSize);
ListFileItem> items = upload.parseRequest(request); // FileUploadException
for(FileItem item : items)
{
if(item.isFormField()) //regular form field
{
String name = item.getFieldName();
String value = item.getString();
%>
h1>%=name%> --> %=value%>/h1>
%
}
else
{ //file upload
String fieldName = item.getFieldName();
String fileName = item.getName();
File uploadedFile = new File(getServletContext().getRealPath("/") +
"fileupload" + File.separator + fieldName + "_" + fileName);
item.write(uploadedFile);
%>
h1>upload file %=uploadedFile.getName()%> done!/h1>
%
}
}
}
%>

Streaming API上傳方式
//fileupload02.htm
復(fù)制代碼 代碼如下:

meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
html>
body>
form method="POST" enctype="multipart/form-data" action="streamingapi.jsp">
File to upload: input type="file" name="file" size="40">br/>
input type="submit" value="Press"> to upload the file!
/form>
/body>
/html>

//streamingapi.jsp
復(fù)制代碼 代碼如下:

%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java"%>
%@page import="java.io.*"%>
%@page import="java.util.List"%>
%@page import="org.apache.commons.fileupload.*"%>
%@page import="org.apache.commons.fileupload.util.Streams"%>
%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
%
request.setCharacterEncoding("UTF-8");
// Check that we have a file upload request
if(ServletFileUpload.isMultipartContent(request))
{
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();

// Parse the request
FileItemIterator iter = upload.getItemIterator(request);
while(iter.hasNext())
{
FileItemStream item = iter.next();
String fieldName = item.getFieldName();
InputStream is = item.openStream();
if(item.isFormField()) //regular form field
{
%>
!-- read a FileItemStream's content into a string. -->
h1>%=fieldName%> --> %=Streams.asString(is)%>/h1>
%
}
else
{ //file upload
String fileName = item.getName();
File uploadedFile = new File(getServletContext().getRealPath("/") +
"fileupload" + File.separator + fieldName + "_" + fileName);
OutputStream os = new FileOutputStream(uploadedFile);
// write file to disk and close outputstream.
Streams.copy(is, os, true);
%>
h1>upload file %=uploadedFile.getName()%> done!/h1>
%
}
}
}
%>

Traditional API vs Streaming API
Streaming API上傳速度相對較快。因?yàn)樗抢脙?nèi)存保存上傳的文件,節(jié)省了傳統(tǒng)API將文件寫入臨時文件帶來的開銷。
可參考:
http://stackoverflow.com/questions/11620432/apache-commons-fileupload-streaming-api
This page describes the traditional API of the commons fileupload library. The traditional API is a convenient approach. However, for ultimate performance, you might prefer the faster Streaming API.
http://commons.apache.org/proper/commons-fileupload/using.html
您可能感興趣的文章:
  • jquery uploadify和apache Fileupload實(shí)現(xiàn)異步上傳文件示例
  • Apache Commons DbUtils工具包使用介紹
  • Apache Commons fileUpload實(shí)現(xiàn)文件上傳之一

標(biāo)簽:白銀 吳忠 黔東 梅州 南充 臨沂 昌都 肇慶

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Apache FileUpload的兩種上傳方式介紹及應(yīng)用》,本文關(guān)鍵詞  Apache,FileUpload,的,兩種,上傳,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Apache FileUpload的兩種上傳方式介紹及應(yīng)用》相關(guān)的同類信息!
  • 本頁收集關(guān)于Apache FileUpload的兩種上傳方式介紹及應(yīng)用的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 男人私gay挠脚心vk视频| 《年轻女教师4》免费观看| 国产又粗又大又硬又长又爽 | 色情一区二区三区免费看| 欧美猛色少妇XXXXXk黄| 日落西山红霞飞| 欧洲VI秘?一区二区三区| 91精品国产色综合久久不卡98口 | ??黄??色??视??频??| 无码人妻精品一区二区三区蝌蚪| 大桥未久1080p| 老熟女浓毛BBwBBwBBw| 成年网站在线看| 免费观看成人久久网免费观看| 健身教练65话如果是你我可以| 厨房婬乱公妇1-42小说| 国产露脸精品国产探花| 男生把坤坤放女生定眼里云开| 一级黄色a| 午夜DJ视频在线观看| 欧美一级特黄级AAA片| 青青草狠狠干| 暖暖视频在线观看日本高清| 福利视频午夜| omega被顶开腔道| 91黑丝视频| 天天干夜夜想| 综漫女主肉肉hhh文| 二次元掀裙子打屁屁到红| 狠狠干女人| 黄色录像一级片| 成品网站源码78w78怎么来的| 成品网站货源1688隐藏入口| 在线观看网站| 国产精品免费网站| 欧美日韩精品AV一区二区| 下面好爽| 免费无遮挡??视频网站西瓜TV| 成人lutube▓无码免费| 中文字幕亚洲专区| 美女视频黄a视频全免费网站下载|