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

java sprinvmvc 文件上传

时间:2017-02-18 18:19:32      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:function   ajax   win   oca   ada   window   type   adapter   .com   

1、配置文件 /wbh-adapter-h5/src/main/resources/dispatcher-servlet.xml

<!-- 文件上传需要配置该句 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

 

2、jquery.form 提交表单;

$(function(){  
    //异步提交表单  
    $("#ajaxSubmit").on("click",function(){  
        console.log($(this));  
        $("#uploadForm").ajaxSubmit({  
            type:‘post‘,  
            url:‘${context}/mobile/uploadimgs‘,  
            success:function(data){  
                console.log(data);  
                var data= eval(data);
    			if(data.errorCode=="1"){
    				 $.alert(data.errorMessage);
    			}else{
    				$.showPreloader(‘编辑成功...‘);
    			      setTimeout(function () {
    			        $.hidePreloader();
    			        window.location.href=‘${context}/weish/index‘;
    			      }, 2000);
    				
    			}
            },  
            error:function(XmlHttpRequest,textStatus,errorThrown){  
                console.log(XmlHttpRequest);  
                console.log(textStatus);  
                console.log(errorThrown);  
                $.showPreloader(‘服务器异常,请重试...‘);
            }  
        });  
    });  
});  

  

后台:

	/**
	 * 上传用户图片,通用
	 * 
	 * @param res 传过来的资源对象
	 * @return 目标对象
	 * @throws Exception 
	 */
	@RequestMapping(value = "/mobile/uploadimgs", method = RequestMethod.POST)
	public @ResponseBody JsonResult uploadimgs(
			HttpServletRequest request,
			HttpServletResponse response,
			com.wbh.adapter.bean.out.user.UserImg userImg,
			@RequestParam(value = "fieldName", required = false) MultipartFile file) {
		JsonResult result = new JsonResult();
		try {
			result = usersService.uploadImgs(userImg, file);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return result;
	}

  

 

java sprinvmvc 文件上传

标签:function   ajax   win   oca   ada   window   type   adapter   .com   

原文地址:http://www.cnblogs.com/hoge/p/6413597.html

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