Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page import="java.util.*" %>
- <%@ page import="org.apache.commons.fileupload.*" %>
- <%@ page import="org.apache.commons.fileupload.disk.*" %>
- <%@ page import="org.apache.commons.fileupload.servlet.*" %>
- <%@ page import="org.apache.commons.io.*" %>
- <%@ page import="java.io.*" %>
- <%
- String destination = "/files";
- String destinationRealPath = application.getRealPath( destination );
- DiskFileItemFactory factory = new DiskFileItemFactory();
- factory.setSizeThreshold( 1024 );
- factory.setRepository( new File( destinationRealPath ) );
- ServletFileUpload uploader = new ServletFileUpload( factory );
- try
- {
- List items = uploader.parseRequest( request );
- Iterator iterator = items.iterator();
- while( iterator.hasNext() )
- {
- FileItem item = (FileItem) iterator.next();
- File file = new File( destinationRealPath, item.getName() );
- item.write( file );
- out.write( "<p>" + file.getName() + " was uploaded successfully</p>" ) ;
- }
- }
- catch( FileUploadException e )
- {
- out.write( "<p>FileUploadException was thrown..." + e.getMessage() + "</p>" );
- }
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement