Created
March 31, 2010 04:29
-
-
Save LeifW/349935 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.servlet.http.*; | |
import javax.servlet.ServletOutputStream; | |
import java.io.InputStream; | |
import org.apache.commons.fileupload.FileItemIterator; | |
import org.apache.commons.fileupload.FileItemStream; | |
import org.apache.commons.fileupload.FileUploadException; | |
import org.apache.commons.fileupload.servlet.ServletFileUpload; | |
public class ExampleServlet extends HttpServlet { | |
ServletFileUpload upload; | |
public void init() { | |
this.upload = new ServletFileUpload(); | |
} | |
doPost(HttpServletRequest req, HttpServletResponse resp) | |
throws ServletException, IOException { | |
FileItemIterator iter = null; | |
FileItemStream item = null; | |
try { | |
iter = upload.getItemIterator(req); | |
} catch (FileUploadException fue) { | |
fue.printStackTrace(); | |
} | |
try { | |
item = iter.next(); | |
} catch (FileUploadException fue) { | |
fue.printStackTrace(); | |
} | |
InputStream in = item.openStream(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of using Apache Commons FileUpload
http://commons.apache.org/fileupload/using.html