标签:
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.ext.js" type="text/javascript"></script>
<script src="js/jquery.form.js" type="text/javascript"></script>
<form action="" method="post" id="jvForm" enctype="multipart/form-data"> <input type="text" name="name"/> <input type="file" name="pic" id="pic"/> <input type="submit" value="提交"/> </form>
<script>
$(function(){
var options = {
url : "upload/uploadPic.do",
dataType : "json",
type : "post",
success : function(data){
alert(2);
}
};
$("#pic").change(function(){
alert(1);
$("#jvForm").ajaxSubmit(options)
});
});
</script
springmvc配置文件处理器:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="1048576"/> </bean>
controller
@Controller @RequestMapping(value = "/upload") public class UploadController { @RequestMapping(value = "/uploadPic.do") public String uploadPic(@RequestParam(required=false) MultipartFile pic){ System.out.println(pic.getOriginalFilename()); return "success"; } }
标签:
原文地址:http://www.cnblogs.com/tuifeideyouran/p/4641188.html