/* NOTE: SORRY ! I posted this, then reviewed it, and discovered I should _NOT_ post the file ( see legal stuff below ). I felt obligated to rip out the Java code and replace it with " // ... " To see the original file go to Sun's Java Web Server site and get the Java WebServer yourself. I'll see if I can get permission to post the file or post some other code that provides the same functionality. Sun has distributed thousands of copies of this file to people outside of Sun -- over the internet -- and yet we can't "disclose" what they've distributed. ( ? ) */ /* * 09/12/97 97/09/12 * * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * * CopyrightVersion 1.0 */ import java.io.IOException; import java.io.File; import java.io.PrintStream; import java.io.ByteArrayOutputStream; import java.util.Hashtable; import java.util.Enumeration; import javax.servlet.*; import javax.servlet.http.*; /** * This is a basic file upload servlet. It will handle file uploads, * as performed by Netscape 3 and 4. Note: This program does not * implement RFC 1867, merely a subset of it. */ public class FileUploadServlet extends HttpServlet { protected int maxSize = // ... public void init( ServletConfig sc ) { // ... } /** * Since fileupload requires POST, we only override this method. */ protected void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { // ... } /** * Obtain information on this servlet. * @return String describing this servlet. */ public String getServletInfo() { return "File upload servlet -- used to receive files"; } /** * The meat of the servlet. This method parses the input, and * returns a hashtable of either String[] values (for parameters) * or Hashtable values (for files uploaded). The values of the entries * in the hashtable are name, filename, Content-Type, and Contents. * Note that uploads should be capped in size by the calling method, since * otherwise a denial of service attack on server memory becomes trivial. */ SECRET parseMulti( String boundary, ServletInputStream in ) throws IOException { // ... note : what it returns, if anything, is a secret. } private void sendFailure( HttpServletResponse res, String reason ) throws IOException { // ... } }