- /doc
- /lib
ㄴ cos.jar
- /src
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="fileFormOk.jsp" method="post" enctype="multipart/form-data">
파일 : <input type="file" name="file">
<input type="submit" value="제출">
</form>
</body>
</html>
<%@page import="java.util.Enumeration"%>
<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//실제 파일이 저장되는 경로
String path = request.getRealPath("fileFolder");
int size = 1024*1024*10; //10M까지 파일 사이즈 가능
String file = "";
String originFile="";
try{
MultipartRequest mult = new MultipartRequest(request, path, size, "UTF-8", new DefaultFileRenamePolicy());
Enumeration files = mult.getFileNames();
String str = (String)files.nextElement();
file = mult.getFilesystemName(str);
originFile = mult.getOriginalFileName(str);
}catch(Exception e){
e.printStackTrace();
}
%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%= file %>
<%= originFile %>
file upload success!
</body>
</html>
실제로 파일이 올라가는 곳은 eclipse상 경로가 아닌 서버 내부에 올라간다.