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

📄 using.html

📁 java 的上传功能很强大的实施上述事实上说是
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">











<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>FileUpload - Using FileUpload</title>
    <style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
    </style>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
          <meta name="author" content="Martin Cooper" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                  <a href="../" id="bannerLeft">
    
                                            <img src="../images/logo.png" alt="" />
    
            </a>
                        <a href="index.html" id="bannerRight">
    
                                            <img src="images/logo.png" alt="" />
    
            </a>
            <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
            
  
    
            <div class="xleft">
        Last Published: 18 January 2008
                  &nbsp;| Version: 1.2.1
                      </div>
            <div class="xright">            <a href="http://www.apachecon.com/" class="externalLink">ApacheCon</a>
            |
                <a href="http://www.apache.org" class="externalLink">Apache</a>
            |
                <a href="../">Commons</a>
            
  

  
    
            
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
            
  
    
                   <h5>Commons FileUpload</h5>
            <ul>
              
    <li class="none">
                    <a href="index.html">Overview</a>
          </li>
              
    <li class="none">
              <strong>User guide</strong>
        </li>
              
    <li class="none">
                    <a href="streaming.html">Streaming API</a>
          </li>
              
    <li class="none">
                    <a href="faq.html">FAQ</a>
          </li>
              
    <li class="none">
                    <a href="apidocs/index.html">Javadoc</a>
          </li>
              
    <li class="none">
                    <a href="mail-lists.html">Mailing lists</a>
          </li>
              
    <li class="none">
                    <a href="team-list.html">Team</a>
          </li>
              
    <li class="none">
                    <a href="tasks.html">Tasks</a>
          </li>
              
    <li class="none">
                    <a href="source-repository.html">SVN repository</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
              
      
            
      
            
      
            
      
            
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="project-info.html">Project Information</a>
                </li>
              
                
              
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
              <h5>Commons</h5>
            <ul>
              
    <li class="none">
                    <a href="../">Home</a>
          </li>
              
                
              
      
              
        <li class="collapsed">
                    <a href="../components.html">Components</a>
                </li>
              
                
              
      
              
        <li class="collapsed">
                    <a href="../sandbox/index.html">Sandbox</a>
                </li>
              
                
              
      
              
        <li class="collapsed">
                    <a href="../dormant/index.html">Dormant</a>
                </li>
              
    <li class="none">
                    <a href="../volunteering.html">Volunteering</a>
          </li>
              
    <li class="none">
                    <a href="../patches.html">Contributing Patches</a>
          </li>
              
    <li class="none">
                    <a href="../building.html">Building Components</a>
          </li>
              
    <li class="none">
                    <a href="../releases/index.html">Releasing Components</a>
          </li>
              
    <li class="none">
                    <a href="http://wiki.apache.org/commons/FrontPage" class="externalLink">Wiki</a>
          </li>
          </ul>
              <h5>ASF</h5>
            <ul>
              
    <li class="none">
                    <a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink">Sponsorship</a>
          </li>
              
    <li class="none">
                    <a href="http://www.apache.org/foundation/thanks.html" class="externalLink">Thanks</a>
          </li>
          </ul>
                                           <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
            
  
    
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section"><h2><a name="Using_FileUpload"></a>Using FileUpload</h2><p>      FileUpload can be used in a number of different ways, depending upon the      requirements of your application. In the simplest case, you will call a      single method to parse the servlet request, and then process the list of      items as they apply to your application. At the other end of the scale,      you might decide to customize FileUpload to take full control of the way      in which individual items are stored; for example, you might decide to      stream the content into a database.    </p><p>      Here, we will describe the basic principles of FileUpload, and illustrate      some of the simpler - and most common - usage patterns. Customization of      FileUpload is described <a href="customizing.html">elsewhere</a>.    </p><p>       FileUpload depends on Commons IO, so make sure you have the version        mentioned on the <a href="dependencies.html">dependencies page</a> in        your classpath before continuing.    </p></div><div class="section"><h2><a name="How_it_works"></a>How it works</h2><p>      A file upload request comprises an ordered list of <em>items</em> that      are encoded according to      <a class="externalLink" href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>,      &quot;Form-based File Upload in HTML&quot;. FileUpload can parse such a request      and provide your application with a list of the individual uploaded      items. Each such item implements the <code>FileItem</code> interface,      regardless of its underlying implementation.    </p><p>      This page describes the traditional API of the commons fileupload      library. The traditional API is a convenient approach. However, for      ultimate performance, you might prefer the faster      <a href="streaming.html">Streaming API</a>.    </p><p>      Each file item has a number of properties that might be of interest for      your application. For example, every item has a name and a content type,      and can provide an <code>InputStream</code> to access its data. On the      other hand, you may need to process items differently, depending upon      whether the item is a regular form field - that is, the data came from      an ordinary text box or similar HTML field - or an uploaded file. The      <code>FileItem</code> interface provides the methods to make such a      determination, and to access the data in the most appropriate manner.    </p><p>      FileUpload creates new file items using a <code>FileItemFactory</code>.      This is what gives FileUpload most of its flexibility. The factory has      ultimate control over how each item is created. The factory implementation      that currently ships with FileUpload stores the item's data in memory or      on disk, depending on the size of the item (i.e. bytes of data). However,      this behavior can be customized to suit your application.    </p></div><div class="section"><h2><a name="Servlets_and_Portlets"></a>Servlets and Portlets</h2><p>      Starting with version 1.1, FileUpload supports file upload requests in      both servlet and portlet environments. The usage is almost identical in      the two environments, so the remainder of this document refers only to      the servlet environment.    </p><p>      If you are building a portlet application, the following are the two      distinctions you should make as you read this document:      <ul><li>          Where you see references to the <code>ServletFileUpload</code> class,          substitute the <code>PortletFileUpload</code> class.        </li><li>          Where you see references to the <code>HttpServletRequest</code> class,          substitute the <code>ActionRequest</code> class.        </li></ul></p></div><div class="section"><h2><a name="Parsing_the_request"></a>Parsing the request</h2><p>      Before you can work with the uploaded items, of course, you need to parse      the request itself. Ensuring that the request is actually a file upload      request is straightforward, but FileUpload makes it simplicity itself, by      providing a static method to do just that.    </p><div class="source"><pre>// Check that we have a file upload requestboolean isMultipart = ServletFileUpload.isMultipartContent(request);</pre></div><p>        Now we are ready to parse the request into its constituent items.      </p><div class="section"><h3><a name="The_simplest_case"></a>The simplest case</h3><p>        The simplest usage scenario is the following:        <ul><li>            Uploaded items should be retained in memory as long as they are            reasonably small.

⌨️ 快捷键说明

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