日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

使用Oreilly上傳組件上傳文件攻略

系統 2074 0

上傳頁面

<% ... @?page?language = " java " ?contentType = " text/html;?charset=GB18030 "
????pageEncoding
= " GB18030 "
%>
<! DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
< meta? http-equiv ="Content-Type" ?content ="text/html;?charset=GB18030" >
< title > Insert?title?here </ title >
</ head >
< body >
< form? name ="form1" ?enctype ="multipart/form-data" ?method ="post" ?action ="file.jsp" >
??上傳文件1:
< input? type ="file" ?name ="file1" ?size ="20" ?maxlength ="20" >< br >
??文件描述1:
< input? type ="text" ?name ="file1" ?size ="20" ?maxlength ="20" >< br >< br >
??上傳文件2:
< input? type ="file" ?name ="file2" ?size ="20" ?maxlength ="20" >< br >
??文件描述2:
< input? type ="text" ?name ="file2" ?size ="20" ?maxlength ="20" >< br >< br >
??上傳文件3:
< input? type ="file" ?name ="file3" ?size ="20" ?maxlength ="20" >< br >
??文件描述3:
< input? type ="text" ?name ="file3" ?size ="20" ?maxlength ="20" >< br >< br >
??
< input? type ="submit" ?value ="submit" />
??
< input? type ="reset" ?value ="reset" />
</ form >
</ body >
</ html >

?處理頁面

?

<% ... @?page?language = " java " ?contentType = " text/html;?charset=GB18030 "
????pageEncoding
= " GB18030 "
%>
<% ... @?page?import = " java.io.*,java.util.*,com.oreilly.servlet.MultipartRequest " ? %>
<% ... @?taglib?prefix = " fmt " ?uri = " http://java.sun.com/jsp/jstl/fmt " ? %>
<! DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
< meta? http-equiv ="Content-Type" ?content ="text/html;?charset=GB18030" >
< title > Insert?title?here </ title >
</ head >
< fmt:requestEncoding? value ="gb2312" />
< body >
<% ...
???
String ?saveDirectory = " /upload " ;? // 設置上傳目錄
???
String ?contextPath = request.getSession().getServletContext().getRealPath(saveDirectory);
???System.out.println(contextPath);
???File?a
= new ?File(contextPath);
???System.out.println(a.isDirectory());
???
if (!a.isDirectory()){
??????a.mkdir();
???}
???
int ?maxPostSize = 5 * 1024 * 1024 ;? // 設定大小為5M
???
String ??filename = null ;
???
String ??contentType = null ;
???
String ??description = null ;
???
int ?count = 0 ;
???MultipartRequest?multi
= new ?MultipartRequest(request,contextPath,maxPostSize);
???
???
???
// 取得所有上傳文件輸入類型名稱及描述
???Enumeration?filesname
= multi.getFileNames();
???Enumeration?filesdesc
= multi.getParameterNames();
???
while (filesname.hasMoreElements()){
?????
String ?name = ( String )filesname.nextElement();
?????
String ?dc = ( String )filesdesc.nextElement();
?????filename
= multi.getFilesystemName(name);
?????contentType
= multi.getContentType(name);
?????description
= multi.getParameter(dc);
?????
if (filename! = null ){
???????count
++ ;
???????
%>
?????????您上傳第
<% = count? %> 個文件: < br >
?????????文件名:
<% = filename? %> < br >
?????????文件類型:
<% = contentType? %> < br >
?????????文件描述:?
<% = description? %> < br >< br >
???????
<% ...
?????}
???}
?
%>
?
您總共上傳
<% = count? %> 個文件
?
</ body >
</ html >

?

?

需要注意兩點:

(1)上傳目錄必須存在

(2)以上代碼暫時不支持中文,支持中文只需要改動
??????? ? String enCoding="gb2312";
??????? ? MultipartRequest multi=new MultipartRequest(request,contextPath,maxPostSize,enCoding);
????



使用Oreilly上傳組件上傳文件攻略


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 东港市| 高青县| 开江县| 区。| 卫辉市| 弋阳县| 吴忠市| 绿春县| 毕节市| 镇巴县| 东台市| 庆安县| 康定县| 衡南县| 通辽市| 内江市| 永春县| 新民市| 乡城县| 阿瓦提县| 莱西市| 兴仁县| 赤水市| 林周县| 罗定市| 兴宁市| 阿克苏市| 海丰县| 华容县| 稻城县| 双牌县| 新化县| 句容市| 古田县| 光山县| 天津市| 手游| 基隆市| 上林县| 平原县| 溧阳市|