1. 程式人生 > >檔案上傳2

檔案上傳2

多檔案上傳
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">
			
			/* 多檔案上傳 */
	function addFile(){
		var div1=document.getElementById("div1");
		div1.innerHTML+="<div><input type='file' name='photo'/><input type='button' value='刪除' onclick='delFile(this)''/></div>";
	} 
	function delFile(input){
		input.parentNode.parentNode.removeChild(input.parentNode);
	}
</script>

</head>
<body>
<form enctype="multipart/form-data"  action="${pageContext.request.contextPath }/uploadServlet" method="post"> 
	<input type="text" name="name"/>
	<div  id=div1>
		<div>																<!-- 點選事件 -->					
		<input type="file" name="photo"/><input type="button" value="新增" onclick="addFile()"/>
		</div>	
		<div>
		<input type="file" name="photo"/><input type="button" value="刪除" onclick="delFile(this)"/>
		</div>	
	</div>
	
	<input type="submit" value="上傳"/>
	
</form>

</body>
</html>