본문 바로가기

jsp

file 업로드

728x90
반응형

파일 전송방식

 

 

클라이언트의 파일 업로드 처리 : 쿼리스트링 전송방식-POST

                                         <form ~~ enctype="multipart/form-data"></form>

 

fileUploadForm.jsp

<%@ 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>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
	$('form').submit(function(){
		var flag = true;
		$('input[type=file]').each(function(idx, inputTag){
			if(!/\.(jpg|jpeg|png|gif)$/.test($(inputTag).val().toLowerCase())){
				alert('이미지 파일 대상 업로드됩니다.');
				flag = false;
			}
		});
		return flag;
	});
});
</script>
</head>
<body>
<!-- 
	클라이언트의 파일 업로드 처리 : 쿼리스트링 전송방식 - POST
							content type = multipart/form-data
	                        <form/>
	                        ajax
	                        * 바이너리 스트리밍을 통한 서버 전송 처리 
	                          (폼필드 - mem_id, mem_pass, ..., 파일)
	                           
 -->
<form action="${pageContext.request.contextPath }/14/result1.jsp"
	method="post" 
	enctype="multipart/form-data">
	
	<table>
		<tr>
			<td>아이디</td>
			<td><input type="text" name="mem_id" /></td>
		</tr>
		<tr>
			<td>패스워드</td>
			<td><input type="text" name="mem_pass"/></td>
		</tr>
		<tr>
			<td>성명</td>
			<td><input type="text" name="mem_name"/></td>
		</tr>
		<tr> 
			<td>파일1</td>
			<td><input type="file" name="files" /></td>
		</tr>
		<tr>
			<td>파일2</td>
			<td><input type="file" name="files"/></td>
		</tr>
		<tr>
			<td colspan="2"><input type="submit" value="전송"></td>
		</tr>
	</table>
</form>
</body>
</html>

 

 

 

commons.apache.org  <- 환경설정?

 

Apache Commons – Apache Commons

Welcome to Apache Commons Apache Commons is an Apache project focused on all aspects of reusable Java components. The Apache Commons project is composed of three parts: The Commons Proper - A repository of reusable Java components. The Commons Sandbox - A

commons.apache.org

 

 

 

 

 

=> 파일을 다운받고 난 뒤  두 파일을 WEB-INF/lib 디렉토리에 복사해준다.

 


클라이언트 파일 업로드 처리

                  

클라이언트(브라우저) 보안정책

: 브라우저는 해당 하드웨어 시스템 내 파일 또는 디렉토리에 접근은 가능하지만

  신규 파일 또는 디렉토리의 생성, 파일 및 디렉토리 수정과 삭제는 불가능하다.

  하지만, IE ActiveX를 활용해서 파일 생성, 수정, 삭제가 가능.

 

서버대상 업로드된 파일의 저장 처리 

 


 

common - utile

 


fileuploadrequestwrapper 클래스 

Override/Implement Methods

 

 

파일 날라가지 않게 하는 방법 ? 

 

http://lo

 

 


util 패키지

FileDownloadView

728x90
반응형

'jsp' 카테고리의 다른 글

struts  (0) 2020.07.06
jsp 두번째 시간  (0) 2020.06.09
jsp 첫 날 수업  (0) 2020.06.08
jsp 환경설정  (0) 2020.06.01