톰캣에서 아래 두 파일은 다운받아서 프로젝트에 추가한다.
commons-fileupload-1.3.jar
commons-io-2.4.jar
1. web.xml 설정은 생략
dispatchservlet를 설정하여 url형식으로 된것만 통과되게 하는놈.
2. beans 설정
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.eLab.Services" />
<mvc:annotation-driven />
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
</beans>
설명 : 자동 주석 해석, 파일 컨트롤의 해석모듈을 추가한다.
@Controller
public class *Controllername{
@RequestMapping(value = "/form", method = RequestMethod.POST)
public @ResponseBody
String handleFormUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file) throws IOException {
InputStream inputStream = file.getInputStream();
File outFile = new File("123.jpg");
System.out.print(outFile.getAbsolutePath());
OutputStream outStream = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len = 0;
while ((len = inputStream.read(buf)) > 0) {
outStream.write(buf, 0, len);
}
outStream.close();
inputStream.close();
return "dd";
}
설명 : 파일명과 패일을 받아서 처리한다.
3.jQuery Form Plugin
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<script src="Script/jquery-1.9.1.js"></script>
<script src="Script/jquery.form.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
jQuery(function($) {
$('#ajaxform1').ajaxForm({
success : function(msg) {
alert(msg);
}
});
});
function uploadfile() {
$('#uploadfile').trigger('click');
}
</script>
</head>
<body>
<h1>Please upload a file</h1>
<form id="ajaxform1" method="post" action="form.do"
enctype="multipart/form-data">
<input type="text" name="name" /> <input type="file" name="file"
id="file_upload" /> <input type="submit" id="uploadfile" />
</form>
<input type="button" value="submit" onclick="uploadfile()" />
</body>
</html>
설명 : 기본 form 호출을 script로 해준다.
제목 | 글쓴이 | 날짜 | 조회 |
---|---|---|---|
2003-09-20 |
11659 |
||
2003-09-20 |
11210 |
||
2003-09-20 |
20253 |
||
지구인 |
2010-08-27 |
19104 |
|
지구인 |
2009-09-07 |
13397 |
|
2010-01-29 |
15414 |
||
2004-10-07 |
16518 |
||
2014-01-11 |
2436 |
||
2014-01-07 |
2595 |
||
2014-01-07 |
2378 |
||
2014-01-07 |
2047 |
||
2960 [공개소스] 그누보드 4.36.27 |
2014-01-07 |
1789 |
|
2959 [공개소스] 그누보드 4.36.26 |
2014-01-07 |
1611 |
|
2958 [공개소스] 그누보드 4.36.25 |
2014-01-07 |
1176 |
|
즐거운개굴 |
2013-09-29 |
3001 |
|
2013-09-03 |
4909 |
||
2955 [웹 프로그래밍] ajax 특수문자 |
2013-08-29 |
5361 |
|
2013-08-26 |
4792 |
||
2013-08-25 |
3634 |
||
2013-08-24 |
4162 |
||
2013-08-23 |
4320 |
||
2013-08-23 |
3592 |
||
2013-08-22 |
1886 |
||
2948 [웹 프로그래밍] log4j |
2013-08-10 |
1622 |
|
2013-08-05 |
2149 |
||
2946 [웹 프로그래밍] Spring 기초 |
2013-08-05 |
2089 |
|
2013-07-30 |
1462 |
||
2013-07-23 |
1941 |