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

📄 fileuploadbase.html

📁 最好的java上传组件
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="171" href="#171">171</a> <a name="172" href="#172">172</a>     <em>/**<em>*</em></em><a name="173" href="#173">173</a> <em>     * The content encoding to use when reading part headers.</em><a name="174" href="#174">174</a> <em>     */</em><a name="175" href="#175">175</a>     <strong>private</strong> String headerEncoding;<a name="176" href="#176">176</a> <a name="177" href="#177">177</a> <a name="178" href="#178">178</a>     <em class="comment">// ----------------------------------------------------- Property accessors</em><a name="179" href="#179">179</a> <a name="180" href="#180">180</a> <a name="181" href="#181">181</a>     <em>/**<em>*</em></em><a name="182" href="#182">182</a> <em>     * Returns the factory class used when creating file items.</em><a name="183" href="#183">183</a> <em>     *</em><a name="184" href="#184">184</a> <em>     * @return The factory class for new file items.</em><a name="185" href="#185">185</a> <em>     */</em><a name="186" href="#186">186</a>     <strong>public</strong> <strong>abstract</strong> <a href="../../../../org/apache/commons/fileupload/FileItemFactory.html">FileItemFactory</a> getFileItemFactory();<a name="187" href="#187">187</a> <a name="188" href="#188">188</a> <a name="189" href="#189">189</a>     <em>/**<em>*</em></em><a name="190" href="#190">190</a> <em>     * Sets the factory class to use when creating file items.</em><a name="191" href="#191">191</a> <em>     *</em><a name="192" href="#192">192</a> <em>     * @param factory The factory class for new file items.</em><a name="193" href="#193">193</a> <em>     */</em><a name="194" href="#194">194</a>     <strong>public</strong> <strong>abstract</strong> <strong>void</strong> setFileItemFactory(<a href="../../../../org/apache/commons/fileupload/FileItemFactory.html">FileItemFactory</a> factory);<a name="195" href="#195">195</a> <a name="196" href="#196">196</a> <a name="197" href="#197">197</a>     <em>/**<em>*</em></em><a name="198" href="#198">198</a> <em>     * Returns the maximum allowed upload size.</em><a name="199" href="#199">199</a> <em>     *</em><a name="200" href="#200">200</a> <em>     * @return The maximum allowed size, in bytes.</em><a name="201" href="#201">201</a> <em>     *</em><a name="202" href="#202">202</a> <em>     * @see #setSizeMax(long)</em><a name="203" href="#203">203</a> <em>     *</em><a name="204" href="#204">204</a> <em>     */</em><a name="205" href="#205">205</a>     <strong>public</strong> <strong>long</strong> getSizeMax() {<a name="206" href="#206">206</a>         <strong>return</strong> sizeMax;<a name="207" href="#207">207</a>     }<a name="208" href="#208">208</a> <a name="209" href="#209">209</a> <a name="210" href="#210">210</a>     <em>/**<em>*</em></em><a name="211" href="#211">211</a> <em>     * Sets the maximum allowed upload size. If negative, there is no maximum.</em><a name="212" href="#212">212</a> <em>     *</em><a name="213" href="#213">213</a> <em>     * @param sizeMax The maximum allowed size, in bytes, or -1 for no maximum.</em><a name="214" href="#214">214</a> <em>     *</em><a name="215" href="#215">215</a> <em>     * @see #getSizeMax()</em><a name="216" href="#216">216</a> <em>     *</em><a name="217" href="#217">217</a> <em>     */</em><a name="218" href="#218">218</a>     <strong>public</strong> <strong>void</strong> setSizeMax(<strong>long</strong> sizeMax) {<a name="219" href="#219">219</a>         <strong>this</strong>.sizeMax = sizeMax;<a name="220" href="#220">220</a>     }<a name="221" href="#221">221</a> <a name="222" href="#222">222</a> <a name="223" href="#223">223</a>     <em>/**<em>*</em></em><a name="224" href="#224">224</a> <em>     * Retrieves the character encoding used when reading the headers of an</em><a name="225" href="#225">225</a> <em>     * individual part. When not specified, or &lt;code>null&lt;/code>, the request</em><a name="226" href="#226">226</a> <em>     * encoding is used. If that is also not specified, or &lt;code>null&lt;/code>,</em><a name="227" href="#227">227</a> <em>     * the platform default encoding is used.</em><a name="228" href="#228">228</a> <em>     *</em><a name="229" href="#229">229</a> <em>     * @return The encoding used to read part headers.</em><a name="230" href="#230">230</a> <em>     */</em><a name="231" href="#231">231</a>     <strong>public</strong> String getHeaderEncoding() {<a name="232" href="#232">232</a>         <strong>return</strong> headerEncoding;<a name="233" href="#233">233</a>     }<a name="234" href="#234">234</a> <a name="235" href="#235">235</a> <a name="236" href="#236">236</a>     <em>/**<em>*</em></em><a name="237" href="#237">237</a> <em>     * Specifies the character encoding to be used when reading the headers of</em><a name="238" href="#238">238</a> <em>     * individual part. When not specified, or &lt;code>null&lt;/code>, the request</em><a name="239" href="#239">239</a> <em>     * encoding is used. If that is also not specified, or &lt;code>null&lt;/code>,</em><a name="240" href="#240">240</a> <em>     * the platform default encoding is used.</em><a name="241" href="#241">241</a> <em>     *</em><a name="242" href="#242">242</a> <em>     * @param encoding The encoding used to read part headers.</em><a name="243" href="#243">243</a> <em>     */</em><a name="244" href="#244">244</a>     <strong>public</strong> <strong>void</strong> setHeaderEncoding(String encoding) {<a name="245" href="#245">245</a>         headerEncoding = encoding;<a name="246" href="#246">246</a>     }<a name="247" href="#247">247</a> <a name="248" href="#248">248</a> <a name="249" href="#249">249</a>     <em class="comment">// --------------------------------------------------------- Public methods</em><a name="250" href="#250">250</a> <a name="251" href="#251">251</a> <a name="252" href="#252">252</a>     <em>/**<em>*</em></em><a name="253" href="#253">253</a> <em>     * 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>">RFC 1867&lt;/a></em><a name="254" href="#254">254</a> <em>     * compliant &lt;code>multipart/form-data&lt;/code> stream.</em><a name="255" href="#255">255</a> <em>     *</em><a name="256" href="#256">256</a> <em>     * @param req The servlet request to be parsed.</em><a name="257" href="#257">257</a> <em>     *</em><a name="258" href="#258">258</a> <em>     * @return A list of &lt;code>FileItem&lt;/code> instances parsed from the</em><a name="259" href="#259">259</a> <em>     *         request, in the order that they were transmitted.</em><a name="260" href="#260">260</a> <em>     *</em><a name="261" href="#261">261</a> <em>     * @throws FileUploadException if there are problems reading/parsing</em><a name="262" href="#262">262</a> <em>     *                             the request or storing files.</em><a name="263" href="#263">263</a> <em>     *</em><a name="264" href="#264">264</a> <em>     * @deprecated Use the method in &lt;code>ServletFileUpload&lt;/code> instead.</em><a name="265" href="#265">265</a> <em>     */</em><a name="266" href="#266">266</a>     <strong>public</strong> List <em class="comment">/*<em class="comment"> <a href="../../../../org/apache/commons/fileupload/FileItem.html">FileItem</a> */</em> parseRequest(HttpServletRequest req)</em><a name="267" href="#267">267</a>             throws <a href="../../../../org/apache/commons/fileupload/FileUploadException.html">FileUploadException</a> {<a name="268" href="#268">268</a>         <strong>return</strong> parseRequest(<strong>new</strong> <a href="../../../../org/apache/commons/fileupload/servlet/ServletRequestContext.html">ServletRequestContext</a>(req));<a name="269" href="#269">269</a>     }<a name="270" href="#270">270</a> <a name="271" href="#271">271</a>     <em>/**<em>*</em></em><a name="272" href="#272">272</a> <em>     * 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>">RFC 1867&lt;/a></em><a name="273" href="#273">273</a> <em>     * compliant &lt;code>multipart/form-data&lt;/code> stream.</em><a name="274" href="#274">274</a> <em>     *</em><a name="275" href="#275">275</a> <em>     * @param ctx The context for the request to be parsed.</em><a name="276" href="#276">276</a> <em>     *</em><a name="277" href="#277">277</a> <em>     * @return A list of &lt;code>FileItem&lt;/code> instances parsed from the</em><a name="278" href="#278">278</a> <em>     *         request, in the order that they were transmitted.</em><a name="279" href="#279">279</a> <em>     *</em><a name="280" href="#280">280</a> <em>     * @throws FileUploadException if there are problems reading/parsing</em><a name="281" href="#281">281</a> <em>     *                             the request or storing files.</em><a name="282" href="#282">282</a> <em>     */</em><a name="283" href="#283">283</a>     <strong>public</strong> List <em class="comment">/*<em class="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="284" href="#284">284</a>             throws <a href="../../../../org/apache/commons/fileupload/FileUploadException.html">FileUploadException</a> {<a name="285" href="#285">285</a>         <strong>if</strong> (ctx == <strong>null</strong>) {<a name="286" href="#286">286</a>             <strong>throw</strong> <strong>new</strong> NullPointerException(<span class="string">"ctx parameter"</span>);<a name="287" href="#287">287</a>         }<a name="288" href="#288">288</a> <a name="289" href="#289">289</a>         ArrayList items = <strong>new</strong> ArrayList();<a name="290" href="#290">290</a>         String contentType = ctx.getContentType();<a name="291" href="#291">291</a> <a name="292" href="#292">292</a>         <strong>if</strong> ((<strong>null</strong> == contentType)<a name="293" href="#293">293</a>             || (!contentType.toLowerCase().startsWith(MULTIPART))) {<a name="294" href="#294">294</a>             <strong>throw</strong> <strong>new</strong> InvalidContentTypeException(<a name="295" href="#295">295</a>                 <span class="string">"the request doesn't contain a "</span><a name="296" href="#296">296</a>                 + MULTIPART_FORM_DATA<a name="297" href="#297">297</a>                 + <span class="string">" or "</span><a name="298" href="#298">298</a>                 + MULTIPART_MIXED<a name="299" href="#299">299</a>                 + <span class="string">" stream, content type header is "</span><a name="300" href="#300">300</a>                 + contentType);<a name="301" href="#301">301</a>         }<a name="302" href="#302">302</a>         <strong>int</strong> requestSize = ctx.getContentLength();<a name="303" href="#303">303</a> <a name="304" href="#304">304</a>         <strong>if</strong> (requestSize == -1) {<a name="305" href="#305">305</a>             <strong>throw</strong> <strong>new</strong> UnknownSizeException(<a name="306" href="#306">306</a>                 <span class="string">"the request was rejected because its size is unknown"</span>);<a name="307" href="#307">307</a>         }<a name="308" href="#308">308</a> <a name="309" href="#309">309</a>         <strong>if</strong> (sizeMax >= 0 &amp;&amp; requestSize > sizeMax) {<a name="310" href="#310">310</a>             <strong>throw</strong> <strong>new</strong> SizeLimitExceededException(<a name="311" href="#311">311</a>                 <span class="string">"the request was rejected because its size ("</span> + requestSize<a name="312" href="#312">312</a>                 + <span class="string">") exceeds the configured maximum ("</span> + sizeMax + <span class="string">")"</span>,<a name="313" href="#313">313</a>                 requestSize, sizeMax);<a name="314" href="#314">314</a>         }<a name="315" href="#315">315</a> <a name="316" href="#316">316</a>         String charEncoding = headerEncoding;<a name="317" href="#317">317</a>         <strong>if</strong> (charEncoding == <strong>null</strong>) {<a name="318" href="#318">318</a>             charEncoding = ctx.getCharacterEncoding();<a name="319" href="#319">319</a>         }<a name="320" href="#320">320</a> <a name="321" href="#321">321</a>         <strong>try</strong> {<a name="322" href="#322">322</a>             byte[] boundary = getBoundary(contentType);<a name="323" href="#323">323</a>             <strong>if</strong> (boundary == <strong>null</strong>) {<a name="324" href="#324">324</a>                 <strong>throw</strong> <strong>new</strong> <a href="../../../../org/apache/commons/fileupload/FileUploadException.html">FileUploadException</a>(<a name="325" href="#325">325</a>                         <span class="string">"the request was rejected because "</span><a name="326" href="#326">326</a>                         + <span class="string">"no multipart boundary was found"</span>);<a name="327" href="#327">327</a>             }<a name="328" href="#328">328</a> <a name="329" href="#329">329</a>             InputStream input = ctx.getInputStream();<a name="330" href="#330">330</a> <a name="331" href="#331">331</a>             <a href="../../../../org/apache/commons/fileupload/MultipartStream.html">MultipartStream</a> multi = <strong>new</strong> <a href="../../../../org/apache/commons/fileupload/MultipartStream.html">MultipartStream</a>(input, boundary);<a name="332" href="#332">332</a>             multi.setHeaderEncoding(charEncoding);<a name="333" href="#333">333</a> <a name="334" href="#334">334</a>             <strong>boolean</strong> nextPart = multi.skipPreamble();<a name="335" href="#335">335</a>             <strong>while</strong> (nextPart) {<a name="336" href="#336">336</a>                 Map headers = parseHeaders(multi.readHeaders());<a name="337" href="#337">337</a>                 String fieldName = getFieldName(headers);<a name="338" href="#338">338</a>                 <strong>if</strong> (fieldName != <strong>null</strong>) {<a name="339" href="#339">339</a>                     String subContentType = getHeader(headers, CONTENT_TYPE);<a name="340" href="#340">340</a>                     <strong>if</strong> (subContentType != <strong>null</strong> &amp;&amp; subContentType<a name="341" href="#341">341</a>                         .toLowerCase().startsWith(MULTIPART_MIXED)) {<a name="342" href="#342">342</a>                         <em class="comment">// Multiple files.</em><a name="343" href="#343">343</a>                         byte[] subBoundary = getBoundary(subContentType);<a name="344" href="#344">344</a>                         multi.setBoundary(subBoundary);<a name="345" href="#345">345</a>                         <strong>boolean</strong> nextSubPart = multi.skipPreamble();<a name="346" href="#346">346</a>                         <strong>while</strong> (nextSubPart) {<a name="347" href="#347">347</a>                             headers = parseHeaders(multi.readHeaders());<a name="348" href="#348">348</a>                             <strong>if</strong> (getFileName(headers) != <strong>null</strong>) {<a name="349" href="#349">349</a>                                 <a href="../../../../org/apache/commons/fileupload/FileItem.html">FileItem</a> item =

⌨️ 快捷键说明

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