파일 업로드 기초 테이블
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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>
<center>
<form action="FileUpload.jsp" enctype="multipart/form-data" method="post">
<table border="1">
<tr><td colspan="2" align="center">파일 업로드</td></tr>
<tr><td align="center">작성자</td> <td><input type="text" name="name"></td></tr>
<tr><td align="center">제목</td> <td><input type="text" name="subject"></td></tr>
<tr><td align="center">파일명 1</td> <td><input type="file" name="filename1"></td></tr>
<tr><td align="center">파일명 2</td> <td><input type="file" name="filename2"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="확인"></td></tr>
</table>
</form>
</center>
</body>
</html>
|
cs |
파일 업로드하는 곳
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
45
46
47
|
<%@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=EUC-KR"
pageEncoding="EUC-KR"%>
<%
String uploadPath = request.getRealPath("FileUpload");
int size = 10*1024*1024;
String name="";
String subject="";
String filename1="";
String filename2="";
try {
MultipartRequest multi = new MultipartRequest(request, uploadPath, size, "euc-kr", new DefaultFileRenamePolicy());
name = multi.getParameter("name");
subject = multi.getParameter("subject");
Enumeration files = multi.getFileNames();
String file1 = (String)files.nextElement();
filename1 = multi.getFilesystemName(file1);
String file2 = (String)files.nextElement();
filename2 = multi.getFilesystemName(file2);
} 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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form name="filecheck" action="FileCheck.jsp" method="post">
<input type="hidden" name="name" value="<%=name %>">
<input type="hidden" name="subject" value="<%=subject %>">
<input type="hidden" name="filename1" value="<%=filename1 %>">
<input type="hidden" name="filename2" value="<%=filename2 %>">
</form>
<a href="#" onclick="javascript:filecheck.submit()">업로드 확인 및 다운로드 페이지 이동</a>
</body>
</html>
|
cs |
파일 업로드 확인하는 곳
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
request.setCharacterEncoding("EUC-KR");
String name = request.getParameter("name");
String subject = request.getParameter("subject");
String filename1 = request.getParameter("filename1");
String filename2 = request.getParameter("filename2");
%>
<!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>
작성자 : <%=name %><br>
제목 : <%=subject %><br>
파일명1 : <a href="FileUpload/<%=filename1 %>"><%=filename1 %></a><br>
파일명2 : <a href="FileUpload/<%=filename2 %>"><%=filename2 %></a><br>
</body>
</html>
|
cs |
'Programming > [JSP]' 카테고리의 다른 글
[JSP] 톰캣으로 프로젝트 실행시 시작페이지 설정 (0) | 2018.05.03 |
---|---|
[JSP] 썸네일 만들기 (0) | 2018.05.01 |
[JSP] template (0) | 2018.04.16 |
[JSP][JAVA BEANS] 회원가입 유효성 검사 (2) | 2018.04.16 |
[JSP] 쇼핑몰에서 장바구니에 담기 (0) | 2018.04.13 |