zoukankan      html  css  js  c++  java
  • 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";
        }
        
    }
  • 相关阅读:
    PAT1065. A+B and C (64bit)
    PAT1064. Complete Binary Search Tree
    PAT 1063. Set Similarity
    CodeForces
    Golang在京东列表页实践总结
    asp.net 5 如何使用ioc 以及在如何获取httpcontext对象
    陨石坑之webapi 使用filter中如何结束请求流
    陨石坑之webapi使用filter
    Socket通信前必须考虑的几件事
    ZeroMQ的进阶
  • 原文地址:https://www.cnblogs.com/tuifeideyouran/p/4641188.html
Copyright © 2011-2022 走看看