91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.63MB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2023-08-31
  • 語言: 其他
  • 標簽: 文件上傳??

資源簡介

能實現多個文件上傳到服務器。eclipse3.2直接導入便可運行。

資源截圖

代碼片段和文件信息

package?com.longtop.picc.fileUpload.servlet;

import?java.io.IOException;
import?java.io.PrintWriter;

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

import?org.apache.commons.fileupload.*;
import?java.util.*;
import?java.util.regex.*;
import?java.io.*;
import?org.apache.commons.fileupload.servlet.*;
import?org.apache.commons.fileupload.disk.DiskFileItemFactory;

public?class?FileUpload?extends?HttpServlet?{

private?String?uploadPath?=?““;?//?用于存放上傳文件的目錄

private?File?tempPath?=?new?File(
“D:\\“);?//?用于存放臨時文件的目錄

public?void?doPost(HttpServletRequest?req?HttpServletResponse?res)
throws?ServletException?IOException?{
res.setContentType(“text/html;?charset=GB18030“);
PrintWriter?out?=?res.getWriter();
System.out.println(req.getContentLength());
System.out.println(req.getContentType());
DiskFileItemFactory?factory?=?new?DiskFileItemFactory();
//?maximum?size?that?will?be?stored?in?memory
//?允許設置內存中存儲數據的門限,單位:字節
factory.setSizeThreshold(4096);
//?the?location?for?saving?data?that?is?larger?than?getSizeThreshold()
//?如果文件大小大于SizeThreshold,則保存到臨時目錄
factory.setRepository(new?File(
“D:\\“));

ServletFileUpload?upload?=?new?ServletFileUpload(factory);
//?maximum?size?before?a?FileUploadException?will?be?thrown
//?最大上傳文件,單位:字節
upload.setSizeMax(1000000);
try?{
List?fileItems?=?upload.parseRequest(req);
//?assume?we?know?there?are?two?files.?The?first?file?is?a?small
//?text?file?the?second?is?unknown?and?is?written?to?a?file?on
//?the?server
Iterator?iter?=?fileItems.iterator();

//?正則匹配,過濾路徑取文件名
String?regExp?=?“.+\\\\(.+)$“;

//?過濾掉的文件類型
String[]?errorType?=?{?“.exe“?“.com“?“.cgi“?“.asp“?};
Pattern?p?=?Pattern.compile(regExp);
String?itemNo?=?““;//?文件存放路徑
while?(iter.hasNext())?{
FileItem?item?=?(FileItem)?iter.next();

//?忽略其他不是文件域的所有表單信息
if?(!item.isFormField())?{
String?name?=?item.getName();
long?size?=?item.getSize();
if?((name?==?null?||?name.equals(““))?&&?size?==?0)
continue;
Matcher?m?=?p.matcher(name);
boolean?result?=?m.find();
if?(result)?{
for?(int?temp?=?0;?temp? if?(m.group(1).endsWith(errorType[temp]))?{
throw?new?IOException(name?+?“:?wrong?type“);
}
}
try?{

//?保存上傳的文件到指定的目錄

//?在下文中上傳文件至數據庫時,將對這里改寫
item.write(new?File(“d:\\“?+?m.group(1)));

out.print(name?+?“  “?+?size?+?“
“);

}?catch?(Exception?e)?{
out.println(e);
}

}?else?{
throw?new?IOException(“fail?to?upload“);
}
}
}
}?catch?(IOException?e)?{
out.println(e);
}?catch?(FileUploadException?e)?{
out.println(e);
}
}

public?void?init()?throws?ServletException?{
t

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件????????472??2009-04-10?10:04??test\.classpath

?????文件????????849??2009-04-10?10:04??test\.project

?????文件????????334??2009-04-10?10:04??test\.settings\org.eclipse.jdt.core.prefs

?????文件????????210??2009-04-10?10:04??test\.settings\org.eclipse.jst.common.project.facet.core.prefs

?????文件????????436??2009-04-10?10:04??test\.settings\org.eclipse.wst.common.component

?????文件????????229??2009-04-10?10:04??test\.settings\org.eclipse.wst.common.project.facet.core.xml

?????文件???????4472??2009-05-19?16:43??test\build\classes\com\longtop\picc\fileUpload\servlet\FileUpload.class

?????文件???????3381??2009-05-19?11:04??test\src\com\longtop\picc\fileUpload\servlet\FileUpload.java

?????文件????????138??2009-05-19?10:57??test\WebContent\images\icon_close.gif

?????文件????????131??2009-05-19?11:01??test\WebContent\images\icon_open.gif

?????文件???????2391??2009-05-19?11:02??test\WebContent\jsp\index.html

?????文件?????????39??2009-04-10?10:04??test\WebContent\meta-INF\MANIFEST.MF

?????文件??????31825??2009-05-19?10:20??test\WebContent\WEB-INF\lib\commons-fileupload.jar

?????文件?????109043??2009-05-19?10:20??test\WebContent\WEB-INF\lib\commons-io-1.4.jar

?????文件????1232111??2009-04-23?16:56??test\WebContent\WEB-INF\lib\iText.jar

?????文件?????331811??2009-04-23?16:56??test\WebContent\WEB-INF\lib\iTextAsian.jar

?????文件??????94457??2009-05-19?10:27??test\WebContent\WEB-INF\lib\javax.servlet.jar

?????文件??????47867??2009-05-19?10:27??test\WebContent\WEB-INF\lib\javax.servlet.jsp.jar

?????文件???????1105??2009-05-19?10:36??test\WebContent\WEB-INF\web.xml

?????目錄??????????0??2009-05-19?16:57??test\build\classes\com\longtop\picc\fileUpload\servlet

?????目錄??????????0??2009-05-19?16:57??test\build\classes\com\longtop\picc\fileUpload

?????目錄??????????0??2009-05-19?16:57??test\src\com\longtop\picc\fileUpload\servlet

?????目錄??????????0??2009-05-19?16:57??test\build\classes\com\longtop\picc

?????目錄??????????0??2009-05-19?16:57??test\src\com\longtop\picc\fileUpload

?????目錄??????????0??2009-05-19?16:57??test\build\classes\com\longtop

?????目錄??????????0??2009-05-19?16:57??test\src\com\longtop\picc

?????目錄??????????0??2009-05-19?16:57??test\build\classes\com

?????目錄??????????0??2009-05-19?16:57??test\src\com\longtop

?????目錄??????????0??2009-05-19?16:57??test\WebContent\WEB-INF\lib

?????目錄??????????0??2009-05-19?16:57??test\build\classes

............此處省略13個文件信息

評論

共有 條評論