・노드js 의 경우에는 외부 모듈이 npm install을 통해 node_modules 폴더에 쌓인다. 일반적으로 자바에서는 어디에 외부 모듈을 저장하는 건지 궁금했는데 WEB-INF안에 저장한다.


・eclipse에서 build path를 보면 알겠지만, eclipse의 web프로젝트는 톰캣의 jar들을 포함한다. 따라서, tomcat 내부에도 내가 실행한 프로젝트 패스들이 생성되어 있다.(C:\apache_tomcat\apache-tomcat-8.5.23\wtpwebapps\helloworld)







・이클립스에서 웹프로젝트를 위한 파일을 구성하면, WebContent에 html,jsp 등의 파일을 구성하는데, WebContent직하에 MultipartRequest모듈 실행시 업로드된 파일이 담기게될 디렉토리 패스를 만들어 놓는다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
    <form action="22fileUpload.jsp" method="post" enctype="multipart/form-data">
        파일 : <input type="file" name="file">
        <input type="submit" value="file uplaod">
    </form>
 
</body>
</html>
cs

・클라이언트 단에서 MultipartRequest을 사용하기 위해선, enctype="multipart/form-data">을 적어주는 것이 필수적이다.

또한 <input type="file" 을 명기하여 file업로드를 위한 input태그임을 알린다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import ="java.util.*"%>
<%@ page import ="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%@ page import ="com.oreilly.servlet.MultipartRequest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
 
<%
    String path = request.getRealPath("uploadedFiles");
    System.out.println(path);
    int size = 1024 * 1024 * 10;
    String file="";
    String oriFile="";
 
    try{
        MultipartRequest multi = new MultipartRequest(request,path,size,"EUC-KR",new DefaultFileRenamePolicy());
        
        Enumeration files = multi.getFileNames();
        String str =(String)files.nextElement();
 
        file = multi.getFilesystemName(str);
        oriFile = multi.getOriginalFileName(str);
        
        System.out.println(file);
        System.out.println(oriFile);
    }
    catch(Exception e){
        e.printStackTrace();
    }
 
 
%>
 
upload success!!
 
<a href="22fileUpload.html">돌아가기</a>
 
</body>
</html>
cs

MultipartRequest multi = new MultipartRequest(request,path,size,"EUC-KR",new DefaultFileRenamePolicy());

로 파일 업로딩은 끝이 난다.

multi.getOriginalFileName(str);은 유저가 업로드한 파일명을 그대로 얻어오는 함수이다.

multi.getFilesystemName(str);은 MultipartRequest모듈 내ㅣ부에서 업로드한 파일명을 얻어오는 함수이다. 

getFilesystemName는 유저가 같은명의 파일을 업로드시 MultipartRequest모듈은 내부로직으로 겹치는 파일명을 수정해주는데, 이 수정된 파일명을 얻어온다.

+ Recent posts