码迷,mamicode.com
首页 > 编程语言 > 详细

Springmvc异步上传文件

时间:2015-07-12 18:52:58      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

<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";
    }
    
}

 

Springmvc异步上传文件

标签:

原文地址:http://www.cnblogs.com/tuifeideyouran/p/4641188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!