﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava--随笔分类-fileupload</title><link>http://www.blogjava.net/leekiang/category/25298.html</link><description>MDA/MDD/TDD/DDD/DDDDDDD</description><language>zh-cn</language><lastBuildDate>Thu, 04 Feb 2010 14:54:54 GMT</lastBuildDate><pubDate>Thu, 04 Feb 2010 14:54:54 GMT</pubDate><ttl>60</ttl><item><title>多文件上传</title><link>http://www.blogjava.net/leekiang/archive/2010/02/02/311732.html</link><dc:creator>leekiang</dc:creator><author>leekiang</author><pubDate>Tue, 02 Feb 2010 14:57:00 GMT</pubDate><guid>http://www.blogjava.net/leekiang/archive/2010/02/02/311732.html</guid><wfw:comment>http://www.blogjava.net/leekiang/comments/311732.html</wfw:comment><comments>http://www.blogjava.net/leekiang/archive/2010/02/02/311732.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/leekiang/comments/commentRss/311732.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/leekiang/services/trackbacks/311732.html</trackback:ping><description><![CDATA[
		<a target="_blank" href="http://code.google.com/p/jquery-transmit/">jquery-transmit</a>:<br />jQuery Multi-file Uploader with Flash<img src ="http://www.blogjava.net/leekiang/aggbug/311732.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/leekiang/" target="_blank">leekiang</a> 2010-02-02 22:57 <a href="http://www.blogjava.net/leekiang/archive/2010/02/02/311732.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>commons-fileupload 1.2发布时的官方声明</title><link>http://www.blogjava.net/leekiang/archive/2008/09/27/231469.html</link><dc:creator>leekiang</dc:creator><author>leekiang</author><pubDate>Sat, 27 Sep 2008 04:34:00 GMT</pubDate><guid>http://www.blogjava.net/leekiang/archive/2008/09/27/231469.html</guid><wfw:comment>http://www.blogjava.net/leekiang/comments/231469.html</wfw:comment><comments>http://www.blogjava.net/leekiang/archive/2008/09/27/231469.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/leekiang/comments/commentRss/231469.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/leekiang/services/trackbacks/231469.html</trackback:ping><description><![CDATA[The Jakarta Commons team is glad to announce the availability of commons-fileupload 1.2. Commons Fileupload is a framework for handling HTTP file upload requests in servlets, portlets, and similar server side Java applications.<br />Compared to the previous version 1.1.1, the following notable changes have been made:<br />    * A streaming API has been added. The streaming API allows to handle arbitrarily large files without intermediary files while still keeping an extremely low memory profile.<br />    * The presence of a content-length header is no longer required.<br />    * Added support for progress listeners.<br />    * Added support for header continuation lines.<br />    * Added support for limiting the actual file size, as opposed to the request size.<br /><br /><img src ="http://www.blogjava.net/leekiang/aggbug/231469.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/leekiang/" target="_blank">leekiang</a> 2008-09-27 12:34 <a href="http://www.blogjava.net/leekiang/archive/2008/09/27/231469.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate处理oracle大字段</title><link>http://www.blogjava.net/leekiang/archive/2008/09/24/230867.html</link><dc:creator>leekiang</dc:creator><author>leekiang</author><pubDate>Wed, 24 Sep 2008 06:01:00 GMT</pubDate><guid>http://www.blogjava.net/leekiang/archive/2008/09/24/230867.html</guid><wfw:comment>http://www.blogjava.net/leekiang/comments/230867.html</wfw:comment><comments>http://www.blogjava.net/leekiang/archive/2008/09/24/230867.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/leekiang/comments/commentRss/230867.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/leekiang/services/trackbacks/230867.html</trackback:ping><description><![CDATA[1,以下是一些零碎的记录，不全。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">字段为java.sql.Blob类型</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Fj fj </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Fj();<br />fj.setAttblob(Hibernate.createBlob(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">]));</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">用empty_blob()替换?</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">session.save(fj);<br />session.flush();<br />session.refresh(fj, LockMode.UPGRADE);<br />org.hibernate.blob.SerializableBlob sb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"><br />(org.hibernate.blob.SerializableBlob) fj.getAttblob();<br />oracle.sql.BLOB blob </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (oracle.sql.BLOB) sb.getWrappedBlob();<br />OutputStream os </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> blob.getBinaryOutputStream();<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">------</span></div><br />2,用jdbc读取CLOB<br />http://hi.baidu.com/xh28025/blog/item/f61c2df1ef8130c47831aa70.html<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">String description </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);"><br />   query </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">select picstr from clobtest_table where id = '001'</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />pstmt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> con.prepareStatement(query);<br />ResultSet result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pstmt.executeQuery();<br /></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(result.next()){<br />   oracle.jdbc.driver.OracleResultSet ors </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"><br />   (oracle.jdbc.driver.OracleResultSet)result;<br />   oracle.sql.CLOB clobtmp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (oracle.sql.CLOB) ors.getClob(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br /><br />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(clobtmp</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> clobtmp.length()</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">){<br />   System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">======CLOB对象为空 </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />   description </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">;<br />   }</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">{<br />   description</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">clobtmp.getSubString((</span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">)clobtmp.length());//从1开始?<br />   System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">======字符串形式 </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">description);<br />   }<br />}</span></div><br /><br /><img src ="http://www.blogjava.net/leekiang/aggbug/230867.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/leekiang/" target="_blank">leekiang</a> 2008-09-24 14:01 <a href="http://www.blogjava.net/leekiang/archive/2008/09/24/230867.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用commons fileupload的零碎笔记</title><link>http://www.blogjava.net/leekiang/archive/2007/08/27/139844.html</link><dc:creator>leekiang</dc:creator><author>leekiang</author><pubDate>Mon, 27 Aug 2007 03:58:00 GMT</pubDate><guid>http://www.blogjava.net/leekiang/archive/2007/08/27/139844.html</guid><wfw:comment>http://www.blogjava.net/leekiang/comments/139844.html</wfw:comment><comments>http://www.blogjava.net/leekiang/archive/2007/08/27/139844.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/leekiang/comments/commentRss/139844.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/leekiang/services/trackbacks/139844.html</trackback:ping><description><![CDATA[我对表单上传的理解(可能有误):<br /> &lt;form action="" method="post" enctype="multipart/form-data"&gt;<br /> 最大上传2G.<br /><a target="_blank" href="http://www.cnblogs.com/kaixuan/archive/2008/01/31/1060284.html">通过 http 协议上传文件(rfc1867协议概述，jsp 应用举例，客户端发送内容构造)</a><br /> 服务器接收到上传的流，自己其实是不作任何处理的，那个request还是原装的,谁来处理这个request呢,一般采用第三方的工具，这里以commons fileupload为例.<br /> <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">DiskFileItemFactory factory </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DiskFileItemFactory();<br />factory.setSizeThreshold(</span><span style="color: rgb(0, 0, 0);">4096</span><span style="color: rgb(0, 0, 0);">);</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 设置缓冲,这个值决定了是fileinputstream还是bytearrayinputstream</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">factory.setRepository(new File(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">d:\\temp</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">设置临时存放目录,默认是new File(System.getProperty("java.io.tmpdir"))</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">ServletFileUpload sfu </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ServletFileUpload(factory);<br />sfu.setSizeMax(</span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">);</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">100M</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">List items </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sfu.parseRequest(request);</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">传入的这个request还是原装的</span></div> 见上面的代码，commons fielupload通过ServletFileUpload类的<span style="color: rgb(0, 0, 0);"><font color="#0000ff">parseRequest(request)<font color="#000000">方法处理这个原始流。而</font></font></span>ServletFileUpload<span style="color: rgb(0, 0, 0);"><font color="#0000ff"><font color="#000000">又会调用其爷爷类FileUploadBase的parseRequest(request)方法，然后又会调return parseRequest(new ServletRequestContext(request)),代码如下<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />            FileItemIterator iter </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getItemIterator(ctx);<br />            List items </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ArrayList();<br />            FileItemFactory fac </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getFileItemFactory();<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (fac </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />                </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> NullPointerException(<br />                    </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">No FileItemFactory has been set.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />            }<br />            </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> (iter.hasNext()) {<br />                FileItemStream item </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iter.next();<br />                FileItem fileItem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> fac.createItem(item.getFieldName(),<br />                        item.getContentType(), item.isFormField(),<br />                        item.getName());<br />                </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />                    Streams.copy(item.openStream(), fileItem.getOutputStream(),<br />                            </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br />                } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (FileUploadIOException e) {<br />                    </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> (FileUploadException) e.getCause();<br />                } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IOException e) {<br />                    </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> IOFileUploadException(//报错经常在这里<br />                            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Processing of </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> MULTIPART_FORM_DATA<br />                            </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> request failed. </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> e.getMessage(), e);<br />                }<br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (fileItem </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> FileItemHeadersSupport) {<br />                    </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> FileItemHeaders fih </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> item.getHeaders();<br />                    ((FileItemHeadersSupport) fileItem).setHeaders(fih);<br />                }<br />                items.add(fileItem);<br />            }<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> items;<br />        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (FileUploadIOException e) {<br />            </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> (FileUploadException) e.getCause();<br />        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IOException e) {<br />            </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileUploadException(e.getMessage(), e);<br />        }<br />    </span></div><br /> 这里注意,<font color="#0000ff">上传的&lt;input type=file</font></font></font></span><font color="#0000ff">&gt;标记一定要有name,如果没有，commons fielupload不作处理</font>。<br /> commons fielupload会把上传的文件以流的方式写入到temp文件夹,临时文件夹可以自己设定，如果不手动设置，则是Servlet容器为web应用分配的临时目录,tomcat可能就是<font color="#ff0000">%TOMCAT_HOME%\temp</font>，我用weblogic时，是<font color="#ff0000">C:\DOCUME~1\yourname\LOCALS~1\Temp\</font>。这些临时文件以"upload"开头，格式是.tmp,例如<font color="#ff0000">"upload_47fdc3_11c9eb678b0__8000_00000043.tmp"</font><br /> 在上传过程中commons fielupload才知道上传的文件的大小，如果你定义允许的最大附件为100M，然后你上传一个200M的文件,那么只有实际传输了100M以后，commons fielupload才知道超过了，然后抛出一个异常(<font color="#ff0000">org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException</font>)。<br /> commons fielupload处理完了以后(处理过程全在<span style="color: rgb(0, 0, 0);"><font color="#0000ff">parseRequest(request)</font>方法里</span>)，返回一个List,里面的每一项已被封装为FileItem,你通过<font color="#0000ff">fileItem.isFormField()</font>判断出是普通的表单属性呢，还是一个文件，如果是文件，你可以从<font color="#0000ff">fileItem.getInputStream()</font>获得输入流，这个输入流其实是一个FileInputStream.当然，如果文件很小，则是ByteArrayInputStream.那么如何区分？这两者的区别是由<font color="#0000ff">factory.setSizeThreshold(4096)</font>确定的。大于4K,为FileInputStream,小于4K为ByteArrayInputStream<br /><br />这样就可以解释struts用ActionForm的方式处理上传附件的一些问题了，struts接收到enctype="multipart/form-data"的post请求后，会看那个对应的action有没有配置actionform，如果配置了，就会作一些处理，所以你在action里得到的request已经不是一个普通的request了，而是一个被封装过的request。如果想得到原始的request，就不要struts-config.xml里给action类配置actionform<br /><br />tempDir指定的目录中可能会随着时间推移出现很多后缀为"tmp"的垃圾文件，commons-fileupload1.2提供了一个不错的解决方法，就是把下面的代码加入到web.xml中即可。<br />&lt;listener&gt;<br />&lt;listener-class&gt;<br />org.apache.commons.fileupload.servlet.FileCleanerCleanup<br />&lt;/listener-class&gt;<br />&lt;/listener&gt; <br />来源:<a target="_blank" href="http://fratemity1314.spaces.live.com/Blog/cns%21E3BCC13A1E72BB4F%21222.entry">http://fratemity1314.spaces.live.com/Blog/cns!E3BCC13A1E72BB4F!222.entry</a><br /><br /><span class="tpc_content">Q:I'm using FileUpload in an Action, but it's not working. Why? <br /><br />A:Struts
recognises multipart requests, and parses them automatically,
presenting the request parameters to your code in the same manner as if
they were regular request parameters. Since struts has already processed the request, and made it available in your form
bean, the input stream is no longer available for parsing, so
attempting to do so with FileUpload will fail. <br /><br />Q:But I need to parse the request myself. How can I do that? <br /><br />A:Struts
parses multipart a request as a part of the process of populating your
form bean from that request. If, for some reason, you need to have full
control over the multipart parsing, you can do so by configuring your
action mapping without an associated form bean. (A better way of doing
this, however, is to replace the default multipart handler with your
own. See the struts documentation for details.) </span><br /><br /><br />1，直接用commons fileupload而不用struts的ActionForm时,表单里的属性值不能用request.getParameter()获取了，而url里的queryString可以。<br />2,  获取form里的属性值的代码<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />                    String formname </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> fi.getFieldName();</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 获取form中的名字</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                    String formcontent </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> fi.getString();<br /><img id="Codehighlighter1_130_247_Open_Image" onclick="this.style.display='none'; Codehighlighter1_130_247_Open_Text.style.display='none'; Codehighlighter1_130_247_Closed_Image.style.display='inline'; Codehighlighter1_130_247_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_130_247_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_130_247_Closed_Text.style.display='none'; Codehighlighter1_130_247_Open_Image.style.display='inline'; Codehighlighter1_130_247_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (formname.equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) </span><span id="Codehighlighter1_130_247_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_130_247_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />                        id </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> formcontent;</span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_284_349_Open_Image" onclick="this.style.display='none'; Codehighlighter1_284_349_Open_Text.style.display='none'; Codehighlighter1_284_349_Closed_Image.style.display='inline'; Codehighlighter1_284_349_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_284_349_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_284_349_Closed_Text.style.display='none'; Codehighlighter1_284_349_Open_Image.style.display='inline'; Codehighlighter1_284_349_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />                    }</span></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (formname.equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) </span><span id="Codehighlighter1_284_349_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_284_349_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />                        title </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> formcontent;<br /><img id="Codehighlighter1_389_463_Open_Image" onclick="this.style.display='none'; Codehighlighter1_389_463_Open_Text.style.display='none'; Codehighlighter1_389_463_Closed_Image.style.display='inline'; Codehighlighter1_389_463_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_389_463_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_389_463_Closed_Text.style.display='none'; Codehighlighter1_389_463_Open_Image.style.display='inline'; Codehighlighter1_389_463_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />                    }</span></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (formname.equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">memo</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) </span><span id="Codehighlighter1_499_561_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_499_561_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />                        memo </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> formcontent;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />                    }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />                </span></div><br />3, 表单里的file控件的name不能为空。<br />4，上传大文件(190多M)时报异常<br />org.apache.commons.fileupload.FileUploadException:   Processing   of  
multipart/form-data   request   failed.   EOF   after   reading   only:
  "3567789 "   of:   "203323339 "   promised   bytes,   out  of   which   at   least:    "0 "   were   already   buffered<br />http://forums.bea.com/thread.jspa?threadID=200033356<br />http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&amp;threadID=20060&amp;start=0&amp;tstart=0<br />http://thisisxy.blogcn.com/diary,204014352.shtml<br />http://www.80diy.com/home/20050527/17/4040711.html<br /><br />5，<br /><span lang="EN-US"><font face="Times New Roman" size="3">org.apache.commons.fileupload.FileUploadException: Processing of multipart/form-data request failed. Read timed out<br /></font></span><font size="3"><span style="font-family: 宋体;"></span><span lang="EN-US"><font face="Times New Roman">HTTP</font></span><span style="font-family: 宋体;">活动超时限制的时间太短 </span></font><span><strong><span class="guitag1">HTTP Keep-Alive Timeout</span></strong></span><span style="font-size: 10.5pt; font-family: Arial;" lang="EN-US">.<br /><br />6,InputStream is =formFile.getInputStream() ;  //formFile是org.apache.struts.upload.FormFile<br />上传的文件小时这个输入流是java.io.ByteArrayInputStream，上传比较大的文件时这个输入流是FileInputStream<br /><br />7,设置表单里的上传路径为只读<br />&lt;input type=file id="uploadfile" name="uploadfile" style="display: none;"&gt;<br />&lt;input type=text id=tempfile readonly="true"&gt;<br />&lt;input type=button <br />onClick="uploadfile.click();tempfile.value=uploadfile.value;" value="浏览.."&gt;<br /><br />10,<br />http://eastpoint.javaeye.com/blog/99084<br />http://topic.csdn.net/u/20080131/13/649c57c7-204e-4bb6-9b09-49cca39f00b8.html<br />http://blog.niwota.com/nb/chenchuang?cat_self_id=291075<br /></span><img src ="http://www.blogjava.net/leekiang/aggbug/139844.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/leekiang/" target="_blank">leekiang</a> 2007-08-27 11:58 <a href="http://www.blogjava.net/leekiang/archive/2007/08/27/139844.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>