Springmvc异步上传文件

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

 

posted on 2015-07-12 17:10  颓废的悠然  阅读(3862)  评论(1编辑  收藏  举报

导航