JAKARTAPROJECT
JAKARTA TIPJSP TIPJSP Áú¹®&´äº¯DATABASE TIPJAVASCRIPT TIPWEBHACKING TIP±âŸ TIP
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ® ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
Commons-Fileupload 1.2
GoodBug http://www.jakartaproject.com
À̹ÌÁö ½½¶óÀÌ´õ º¸±â

Commons-Fileupload 1.2

 

1.2 ¹öÁ¯ÀÌ 2007.2.13¿¡ »õ·Ó°Ô¹èÆ÷µÇ¾ú½À´Ï´Ù

1.1 ÀÌÇÏ´Ü°è ¹öÁ¯°ú ´Þ¶óÁø Á¡À» ¾Ë¾Æº¸µµ·Ï ÇÏÁö¿ä

 

I. commons-fileupload 1.1

http://www.jakartaproject.com/article/jakarta/110887666654000

 

 

II. ´Ù¿î·Îµå ¹× ¼³Ä¡

 -. fileupload´Â commonsÀÇ io°¡ ÇÊ¿äÇÕ´Ï´Ù

¨ç commons-fileupload

http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi

¨è commons-io

http://jakarta.apache.org/site/downloads/downloads_commons-io.cgi

 

 

III. ´Þ¶óÁøÁ¡

 -. DiskFileUpload °¡ Deprecated µÇ¾ú½À´Ï´Ù

 -. ¸®½º³Ê Ãß°¡¸¦ ÅëÇØ ¾÷·Îµå ÁøÇà »óŸ¦ ÆľÇÇÒ ¼ö ÀÖ½À´Ï´Ù(´ë¿ë·® ÆÄÀÏÀÎ °æ¿ì À¯¿ë)

 -. ºñÁ¤»óÀûÀÎ ¾÷·Îµå½Ã ³ªÅ¸³ª´Â Áß°£ ¾²·¹±â ÆÄÀϵéÀ» Á¦°ÅÇÒ ¼ö ÀÖ½À´Ï´Ù

 

IV. ¿¹Á¦¼Ò½ºÄÚµå


upload.html

<form name=fileupload method=post action=./upload enctype="multipart/form-data">
 file : <input type=file name=file1><br>
 text : <input type=text name=text1><br>
 <input type=submit name=button1 value=submit>
</form>

 

web.xml

°¡ºñÁö ÆÄÀÏ cleaner¿¡ »ç¿ëµÇ´Â FileCleanerCleanupÀ» listener·Î Ãß°¡

»ùÇà Äڵ忡¼­ »ç¿ëµÇ´Â ¼­ºí¸´ µî·Ï

<web-app>

   ...

  

   <listener>
       <listener-class>
           org.apache.commons.fileupload.servlet.FileCleanerCleanup
       </listener-class>
   </listener>

 

    ...

 

    <servlet>
        <servlet-name>uploadServlet</servlet-name>
        <servlet-class>UploadServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>uploadServlet</servlet-name>
        <url-pattern>/upload</url-pattern>
    </servlet-mapping>

    ...

</web-app>

 

UploadServlet.java

 

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;


public class UploadServlet extends HttpServlet {
   
    String upload_dir = null;
    public void init(ServletConfig config) throws ServletException {
          super.init(config); 
          upload_dir = config.getServletContext().getRealPath("/upload/");
    }

 

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   

        // form typeÀÌ multipart/form-data ¸é true ±×·¸Áö ¾ÊÀ¸¸é false¸¦ ¹Ýȯ
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
       
        if (isMultipart) {
            try {

                int yourMaxMemorySize = 1024 * 10;                 // threshold  °ª ¼³Á¤
                long yourMaxRequestSize = 1024 * 1024 * 100;   //¾÷·Îµå ÃÖ´ë »çÀÌÁî ¼³Á¤ (100M)

                File yourTempDirectory = new File(upload_dir);
               
                DiskFileItemFactory factory = new DiskFileItemFactory();
                factory.setSizeThreshold(yourMaxMemorySize);
                factory.setRepository(yourTempDirectory);               
   
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(yourMaxRequestSize);          // Àӽà ¾÷·Îµå µð·ºÅ丮 ¼³Á¤
                upload.setHeaderEncoding("EUC_KR");               // ÀÎÄÚµù ¼³Á¤
                

                /**

                 *  ¾÷·Îµå ÁøÇà »óÅ Ãâ·Â (Watching progress)

                */
                ProgressListener progressListener = new ProgressListener(){
                   private long megaBytes = -1;
                   public void update(long pBytesRead, long pContentLength, int pItems) {
                       long mBytes = pBytesRead / 1000000;
                       if (megaBytes == mBytes) {
                           return;
                       }
                       megaBytes = mBytes;
                       System.out.println("We are currently reading item " + pItems);
                       if (pContentLength == -1) {
                           System.out.println("So far, " + pBytesRead + " bytes have been read.");
                       } else {
                           System.out.println("So far, " + pBytesRead + " of " + pContentLength
                                              + " bytes have been read.");
                       }
                   }
                };
                upload.setProgressListener(progressListener);   // ÁøÇà»óÅ ¸®½º³Ê Ãß°¡
    

                String fieldName = null;
                String fieldValue = null;
                String fileName = null;
                String contentType = null;
                long sizeInBytes = 0;

                List items = upload.parseRequest(request);               
                Iterator iter = items.iterator();
                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();
   

                    // Á¤»óÀûÀÎ Æû°ª Ãâ·Â ¹× ó¸®
                    if (item.isFormField()) {
                        fieldName = item.getFieldName();
                        fieldValue = item.getString();
                       
                        System.out.println("-----+-----+-----+-----+-----+-----+-----+-----");
                        System.out.println("Field Name : "+fieldName);
                        System.out.println("Field Value : "+fieldValue);
                        System.out.println("-----+-----+-----+-----+-----+-----+-----+-----");
                       

                    // ¾÷·Îµå ÆÄÀÏ Ã³¸®
                    } else {
                        fieldName = item.getFieldName();
                        fileName = item.getName();
                        contentType = item.getContentType();
                        sizeInBytes = item.getSize();
                       
                        System.out.println("-----+-----+-----+-----+-----+-----+-----+-----");
                        System.out.println("Field Name : "+fieldName);
                        System.out.println("File Name : "+fileName);
                        System.out.println("ContentType : "+contentType);
                        System.out.println("File Size : "+sizeInBytes);
                        System.out.println("-----+-----+-----+-----+-----+-----+-----+-----");

                        String savefile = fileName.substring(fileName.lastIndexOf("\\")+1, fileName.length());
                        File uploadedFile = new File(upload_dir+"\\"+savefile);
                        item.write(uploadedFile);
                    }
                }

 

            // ¼³Á¤ÇÑ ¾÷·Îµå »çÀÌÁî ÃÊ°ú½Ã exception ó¸®
            } catch (SizeLimitExceededException e) {
                e.printStackTrace();   

            // ¾÷·Îµå½Ã ioµî ÀÌ»ó exception ó¸®
            } catch (FileUploadException e) {
                e.printStackTrace();

            // ±âŸ exception ó¸®
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }   
}

 

V. ½ÇÇà°á°ú

-----+-----+-----+-----+-----+-----+-----+-----+-----
Field Name : file1
File Name : C:\Program Backup\AromNet11a\AromNet.exe
ContentType : application/octet-stream
File Size : 274432
-----+-----+-----+-----+-----+-----+-----+-----+-----
-----+-----+-----+-----+-----+-----+-----+-----+-----
Field Name : text1
Field Value : this is test
-----+-----+-----+-----+-----+-----+-----+-----+-----

 

Å« ÆÄÀÏÀ» ¾÷·ÎµåÇÑ °æ¿ì ¾÷·Îµå »óÅ Ãâ·Â

We are currently reading item 0
So far, 4096 of 338043623 bytes have been read.
We are currently reading item 1
So far, 1003477 of 338043623 bytes have been read.
We are currently reading item 1
So far, 2002901 of 338043623 bytes have been read.
We are currently reading item 1
So far, 3002325 of 338043623 bytes have been read.
We are currently reading item 1
So far, 4001749 of 338043623 bytes have been read.
We are currently reading item 1
So far, 5001173 of 338043623 bytes have been read.
We are currently reading item 1
So far, 6000597 of 338043623 bytes have been read.
We are currently reading item 1
So far, 7000021 of 338043623 bytes have been read.
We are currently reading item 1
So far, 8003498 of 338043623 bytes have been read.
We are currently reading item 1
So far, 9002922 of 338043623 bytes have been read.
We are currently reading item 1
So far, 10002346 of 338043623 bytes have been read.
We are currently reading item 1
So far, 11001770 of 338043623 bytes have been read.
We are currently reading item 1
So far, 12001194 of 338043623 bytes have been read.
We are currently reading item 1
So far, 13000618 of 338043623 bytes have been read.
We are currently reading item 1
So far, 14000042 of 338043623 bytes have been read.
We are currently reading item 1
So far, 15003605 of 338043623 bytes have been read.
We are currently reading item 1
So far, 16003029 of 338043623 bytes have been read.

...

 

=============================================

º»¹®¼­´Â ÀÚÀ¯·Ó°Ô ¹èÆ÷/º¹»ç ÇÒ¼ö ÀÖÁö¸¸

À̹®¼­ÀÇ ÀúÀÚ¿¡ ´ëÇÑ ¾ð±ÞÀ» »èÁ¦ÇÏ½Ã¸é ¾ÈµË´Ï´Ù

ÀúÀÚ : GoodBug (unicorn@jakartaproject.com)

ÃÖÃÊ : http://www.jakartaproject.com 

=============================================

 

2007-12-07 15:37:50
211.189.124.***

 

ÁÁÀº»ý°¢ ^^

÷ºÎÆÄÀÏ (ÃÑ 1°³)
  1. 2007-04-23 PM 02-10-18.jpg 32.58 KB (178 ´Ù¿î·Îµå)
10Á¡ (2¸í)
µ¡±Û 1°³ | ÅÂ±× 2°³ | °ü·Ã±Ûº¸±â
ű×ÀÔ·Â
½±Ç¥(,)±¸ºÐÀ¸·Î Çѹø¿¡ ¿©·¯ ű׸¦ ÀÔ·ÂÇÒ¼ö ÀÖ½À´Ï´Ù
upload (3) dd (5)
´ÞÆØÀÌ
(0) (0)
¸ÚÁö½Ê´Ï´Ù ^^b
222.251.210.*** 2007-04-29 21:09:41
À̸§ ºñ¹Ð¹øÈ£
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ® ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
! ¹øÈ£ Á¦¸ñ ±Û¾´ÀÌ ÀÏÀÚ Á¶È¸
Hierarchy of the Apache Software Foundation GoodBug 2005-10-14 10,814
Jakarta Project °­Á °Ô½ÃÆÇÀÔ´Ï´Ù 8 GoodBug 2005-04-03 11,701
44 Log4J log4j¿¡¼­ e.printStackTrace() ¸Þ½ÃÁö¸¦ log¿¡ ³²±â´Â ¹æ¹ý 1 kaiser 2008-10-22 17,613
43 DBUtils DBUtils¿¡¼­ Clob »ç¿ëÇϱâ 3 1 GoodBug 2007-08-28 10,633
42 Spring Spring ¼³Á¤ ÆÄÀÏ ·Îµù 1 GoodBug 2007-07-16 11,317
41 POI POIÀÇ HSLF¸¦ ÀÌ¿ëÇÏ¿© PowerPoint ¹®¼­¸¦ ÀоÀÚ 2 GoodBug 2007-05-28 14,910
40 POI POIÀÇ HWPF¸¦ ÀÌ¿ëÇÏ¿© MS WORD¹®¼­¸¦ ÀоÀÚ 2 GoodBug 2007-05-28 16,839
39 Validator Validator ¼Ó¼ºµé 1 GoodBug 2007-05-11 10,404
dd Commons-Fileupload 1.2 1 2 GoodBug 2007-04-23 15,345
37 Apache Apache2 + Tomcat5.5 + mod_jk 4 ¹ÙÀÌ·¯½ºô¸国 2007-01-29 11,066
36 DBUtils DBUtils¿¡¼­ number ŸÀÔÀÇ Ä÷³ÀÌ intÇüÀ¸·Î ¾È³Ñ¾î¿Ã¶§.. 3 1 GoodBug 2006-06-28 10,755
35 ÈìÈì À§ÇèÇÑ static Logger Çʵå... 2 1 ¼­¿¬¾Æºü 2006-03-16 10,113
34 Installing Tomcat with commons-daemon (jsvc) GoodBug 2006-01-08 9,067
33 commons Commons DbUtils ¸î°¡Áö ¿¹Á¦ 3 2 GoodBug 2005-11-17 15,221
32 commons Jakarta Commons Net ¿¡¼­ FTP »ç¿ë½Ã ¸ñ·ÏÀÌ ¾Èº¸ÀÏ °æ¿ì 2 GoodBug 2005-11-15 21,776
31 listFiles() ¿¡¼­ null À» ¹Ýȯ ÃßÀû.. ½Å¸¸µÎ 2008-11-11 11,866
30 commons ¸ñ·ÏÀÌ ¾Èº¸ÀÏ °æ¿ì ÇØ°á±â Iź 1 2 GoodBug 2005-12-23 15,932
29 POI POI·Î ¿¢¼¿ÆÄÀÏ ÀÐÀ»¶§, Invalid header signature ¿¡·¯ 1 GoodBug 2005-11-12 16,540
28 log4j log4j, JSP¿¡¼­ ¿øÇÏ´Â Appender °ñ¶ó¾²±â 1 GoodBug 2005-11-07 13,894
27 commons Commons-Email~ 7 2 GoodBug 2005-10-13 17,860
copyright 2005-2024 by Unicorn