⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileuploadbase.html

📁 java 的上传功能很强大的实施上述事实上说是
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="239" href="#239">239</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setSizeMax(<strong class="jxr_keyword">long</strong> sizeMax) {<a name="240" href="#240">240</a>         <strong class="jxr_keyword">this</strong>.sizeMax = sizeMax;<a name="241" href="#241">241</a>     }<a name="242" href="#242">242</a> <a name="243" href="#243">243</a>     <em class="jxr_javadoccomment">/**</em><a name="244" href="#244">244</a> <em class="jxr_javadoccomment">     * Returns the maximum allowed size of a single uploaded file,</em><a name="245" href="#245">245</a> <em class="jxr_javadoccomment">     * as opposed to {@link #getSizeMax()}.</em><a name="246" href="#246">246</a> <em class="jxr_javadoccomment">     *</em><a name="247" href="#247">247</a> <em class="jxr_javadoccomment">     * @see #setFileSizeMax(long)</em><a name="248" href="#248">248</a> <em class="jxr_javadoccomment">     * @return Maximum size of a single uploaded file.</em><a name="249" href="#249">249</a> <em class="jxr_javadoccomment">     */</em><a name="250" href="#250">250</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getFileSizeMax() {<a name="251" href="#251">251</a>         <strong class="jxr_keyword">return</strong> fileSizeMax;<a name="252" href="#252">252</a>     }<a name="253" href="#253">253</a> <a name="254" href="#254">254</a>     <em class="jxr_javadoccomment">/**</em><a name="255" href="#255">255</a> <em class="jxr_javadoccomment">     * Sets the maximum allowed size of a single uploaded file,</em><a name="256" href="#256">256</a> <em class="jxr_javadoccomment">     * as opposed to {@link #getSizeMax()}.</em><a name="257" href="#257">257</a> <em class="jxr_javadoccomment">     *</em><a name="258" href="#258">258</a> <em class="jxr_javadoccomment">     * @see #getFileSizeMax()</em><a name="259" href="#259">259</a> <em class="jxr_javadoccomment">     * @param fileSizeMax Maximum size of a single uploaded file.</em><a name="260" href="#260">260</a> <em class="jxr_javadoccomment">     */</em><a name="261" href="#261">261</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setFileSizeMax(<strong class="jxr_keyword">long</strong> fileSizeMax) {<a name="262" href="#262">262</a>         <strong class="jxr_keyword">this</strong>.fileSizeMax = fileSizeMax;<a name="263" href="#263">263</a>     }<a name="264" href="#264">264</a> <a name="265" href="#265">265</a>     <em class="jxr_javadoccomment">/**</em><a name="266" href="#266">266</a> <em class="jxr_javadoccomment">     * Retrieves the character encoding used when reading the headers of an</em><a name="267" href="#267">267</a> <em class="jxr_javadoccomment">     * individual part. When not specified, or &lt;code&gt;null&lt;/code&gt;, the request</em><a name="268" href="#268">268</a> <em class="jxr_javadoccomment">     * encoding is used. If that is also not specified, or &lt;code&gt;null&lt;/code&gt;,</em><a name="269" href="#269">269</a> <em class="jxr_javadoccomment">     * the platform default encoding is used.</em><a name="270" href="#270">270</a> <em class="jxr_javadoccomment">     *</em><a name="271" href="#271">271</a> <em class="jxr_javadoccomment">     * @return The encoding used to read part headers.</em><a name="272" href="#272">272</a> <em class="jxr_javadoccomment">     */</em><a name="273" href="#273">273</a>     <strong class="jxr_keyword">public</strong> String getHeaderEncoding() {<a name="274" href="#274">274</a>         <strong class="jxr_keyword">return</strong> headerEncoding;<a name="275" href="#275">275</a>     }<a name="276" href="#276">276</a> <a name="277" href="#277">277</a> <a name="278" href="#278">278</a>     <em class="jxr_javadoccomment">/**</em><a name="279" href="#279">279</a> <em class="jxr_javadoccomment">     * Specifies the character encoding to be used when reading the headers of</em><a name="280" href="#280">280</a> <em class="jxr_javadoccomment">     * individual part. When not specified, or &lt;code&gt;null&lt;/code&gt;, the request</em><a name="281" href="#281">281</a> <em class="jxr_javadoccomment">     * encoding is used. If that is also not specified, or &lt;code&gt;null&lt;/code&gt;,</em><a name="282" href="#282">282</a> <em class="jxr_javadoccomment">     * the platform default encoding is used.</em><a name="283" href="#283">283</a> <em class="jxr_javadoccomment">     *</em><a name="284" href="#284">284</a> <em class="jxr_javadoccomment">     * @param encoding The encoding used to read part headers.</em><a name="285" href="#285">285</a> <em class="jxr_javadoccomment">     */</em><a name="286" href="#286">286</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setHeaderEncoding(String encoding) {<a name="287" href="#287">287</a>         headerEncoding = encoding;<a name="288" href="#288">288</a>     }<a name="289" href="#289">289</a> <a name="290" href="#290">290</a> <a name="291" href="#291">291</a>     <em class="jxr_comment">// --------------------------------------------------------- Public methods</em><a name="292" href="#292">292</a> <a name="293" href="#293">293</a> <a name="294" href="#294">294</a>     <em class="jxr_javadoccomment">/**</em><a name="295" href="#295">295</a> <em class="jxr_javadoccomment">     * Processes an &lt;a href="<a href="http://www.ietf.org/rfc/rfc1867.txt" target="alexandria_uri">http://www.ietf.org/rfc/rfc1867.txt</a>"&gt;RFC 1867&lt;/a&gt;</em><a name="296" href="#296">296</a> <em class="jxr_javadoccomment">     * compliant &lt;code&gt;multipart/form-data&lt;/code&gt; stream.</em><a name="297" href="#297">297</a> <em class="jxr_javadoccomment">     *</em><a name="298" href="#298">298</a> <em class="jxr_javadoccomment">     * @param req The servlet request to be parsed.</em><a name="299" href="#299">299</a> <em class="jxr_javadoccomment">     *</em><a name="300" href="#300">300</a> <em class="jxr_javadoccomment">     * @return A list of &lt;code&gt;FileItem&lt;/code&gt; instances parsed from the</em><a name="301" href="#301">301</a> <em class="jxr_javadoccomment">     *         request, in the order that they were transmitted.</em><a name="302" href="#302">302</a> <em class="jxr_javadoccomment">     *</em><a name="303" href="#303">303</a> <em class="jxr_javadoccomment">     * @throws FileUploadException if there are problems reading/parsing</em><a name="304" href="#304">304</a> <em class="jxr_javadoccomment">     *                             the request or storing files.</em><a name="305" href="#305">305</a> <em class="jxr_javadoccomment">     *</em><a name="306" href="#306">306</a> <em class="jxr_javadoccomment">     * @deprecated Use the method in &lt;code&gt;ServletFileUpload&lt;/code&gt; instead.</em><a name="307" href="#307">307</a> <em class="jxr_javadoccomment">     */</em><a name="308" href="#308">308</a>     <strong class="jxr_keyword">public</strong> List <em class="jxr_comment">/*<em class="jxr_comment"> <a href="../../../../org/apache/commons/fileupload/FileItem.html">FileItem</a> */</em> parseRequest(HttpServletRequest req)</em><a name="309" href="#309">309</a>     <strong class="jxr_keyword">throws</strong> <a href="../../../../org/apache/commons/fileupload/FileUploadException.html">FileUploadException</a> {<a name="310" href="#310">310</a>         <strong class="jxr_keyword">return</strong> parseRequest(<strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/commons/fileupload/servlet/ServletRequestContext.html">ServletRequestContext</a>(req));<a name="311" href="#311">311</a>     }<a name="312" href="#312">312</a> <a name="313" href="#313">313</a>     <em class="jxr_javadoccomment">/**</em><a name="314" href="#314">314</a> <em class="jxr_javadoccomment">     * Processes an &lt;a href="<a href="http://www.ietf.org/rfc/rfc1867.txt" target="alexandria_uri">http://www.ietf.org/rfc/rfc1867.txt</a>"&gt;RFC 1867&lt;/a&gt;</em><a name="315" href="#315">315</a> <em class="jxr_javadoccomment">     * compliant &lt;code&gt;multipart/form-data&lt;/code&gt; stream.</em><a name="316" href="#316">316</a> <em class="jxr_javadoccomment">     *</em><a name="317" href="#317">317</a> <em class="jxr_javadoccomment">     * @param ctx The context for the request to be parsed.</em><a name="318" href="#318">318</a> <em class="jxr_javadoccomment">     *</em><a name="319" href="#319">319</a> <em class="jxr_javadoccomment">     * @return An iterator to instances of &lt;code&gt;FileItemStream&lt;/code&gt;</em><a name="320" href="#320">320</a> <em class="jxr_javadoccomment">     *         parsed from the request, in the order that they were</em><a name="321" href="#321">321</a> <em class="jxr_javadoccomment">     *         transmitted.</em><a name="322" href="#322">322</a> <em class="jxr_javadoccomment">     *</em><a name="323" href="#323">323</a> <em class="jxr_javadoccomment">     * @throws FileUploadException if there are problems reading/parsing</em><a name="324" href="#324">324</a> <em class="jxr_javadoccomment">     *                             the request or storing files.</em><a name="325" href="#325">325</a> <em class="jxr_javadoccomment">     * @throws IOException An I/O error occurred. This may be a network</em><a name="326" href="#326">326</a> <em class="jxr_javadoccomment">     *   error while communicating with the client or a problem while</em><a name="327" href="#327">327</a> <em class="jxr_javadoccomment">     *   storing the uploaded content.</em><a name="328" href="#328">328</a> <em class="jxr_javadoccomment">     */</em><a name="329" href="#329">329</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../org/apache/commons/fileupload/FileItemIterator.html">FileItemIterator</a> getItemIterator(<a href="../../../../org/apache/commons/fileupload/RequestContext.html">RequestContext</a> ctx)<a name="330" href="#330">330</a>     <strong class="jxr_keyword">throws</strong> FileUploadException, IOException {<a name="331" href="#331">331</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/commons/fileupload/FileUploadBase.html">FileItemIteratorImpl</a>(ctx);<a name="332" href="#332">332</a>     }<a name="333" href="#333">333</a> <a name="334" href="#334">334</a>     <em class="jxr_javadoccomment">/**</em><a name="335" href="#335">335</a> <em class="jxr_javadoccomment">     * Processes an &lt;a href="<a href="http://www.ietf.org/rfc/rfc1867.txt" target="alexandria_uri">http://www.ietf.org/rfc/rfc1867.txt</a>"&gt;RFC 1867&lt;/a&gt;</em><a name="336" href="#336">336</a> <em class="jxr_javadoccomment">     * compliant &lt;code&gt;multipart/form-data&lt;/code&gt; stream.</em><a name="337" href="#337">337</a> <em class="jxr_javadoccomment">     *</em><a name="338" href="#338">338</a> <em class="jxr_javadoccomment">     * @param ctx The context for the request to be parsed.</em><a name="339" href="#339">339</a> <em class="jxr_javadoccomment">     *</em><a name="340" href="#340">340</a> <em class="jxr_javadoccomment">     * @return A list of &lt;code&gt;FileItem&lt;/code&gt; instances parsed from the</em><a name="341" href="#341">341</a> <em class="jxr_javadoccomment">     *         request, in the order that they were transmitted.</em><a name="342" href="#342">342</a> <em class="jxr_javadoccomment">     *</em><a name="343" href="#343">343</a> <em class="jxr_javadoccomment">     * @throws FileUploadException if there are problems reading/parsing</em><a name="344" href="#344">344</a> <em class="jxr_javadoccomment">     *                             the request or storing files.</em><a name="345" href="#345">345</a> <em class="jxr_javadoccomment">     */</em><a name="346" href="#346">346</a>     <strong class="jxr_keyword">public</strong> List <em class="jxr_comment">/*<em class="jxr_comment"> <a href="../../../../org/apache/commons/fileupload/FileItem.html">FileItem</a> */</em> parseRequest(<a href="../../../../org/apache/commons/fileupload/RequestContext.html">RequestContext</a> ctx)</em><a name="347" href="#347">347</a>             <strong class="jxr_keyword">throws</strong> <a href="../../../../org/apache/commons/fileupload/FileUploadException.html">FileUploadException</a> {<a name="348" href="#348">348</a>         <strong class="jxr_keyword">try</strong> {<a name="349" href="#349">349</a>             <a href="../../../../org/apache/commons/fileupload/FileItemIterator.html">FileItemIterator</a> iter = getItemIterator(ctx);<a name="350" href="#350">350</a>             List items = <strong class="jxr_keyword">new</strong> ArrayList();<a name="351" href="#351">351</a>             <a href="../../../../org/apache/commons/fileupload/FileItemFactory.html">FileItemFactory</a> fac = getFileItemFactory();<a name="352" href="#352">352</a>             <strong class="jxr_keyword">if</strong> (fac == <strong class="jxr_keyword">null</strong>) {<a name="353" href="#353">353</a>                 <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> NullPointerException(<a name="354" href="#354">354</a>                     <span class="jxr_string">"No FileItemFactory has been set."</span>);<a name="355" href="#355">355</a>             }<a name="356" href="#356">356</a>             <strong class="jxr_keyword">while</strong> (iter.hasNext()) {<a name="357" href="#357">357</a>                 <a href="../../../../org/apache/commons/fileupload/FileItemStream.html">FileItemStream</a> item = iter.next();<a name="358" href="#358">358</a>                 <a href="../../../../org/apache/commons/fileupload/FileItem.html">FileItem</a> fileItem = fac.createItem(item.getFieldName(),<a name="359" href="#359">359</a>                         item.getContentType(), item.isFormField(),<a name="360" href="#360">360</a>                         item.getName());<a name="361" href="#361">361</a>                 <strong class="jxr_keyword">try</strong> {<a name="362" href="#362">362</a>                     Streams.copy(item.openStream(), fileItem.getOutputStream(),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -