Spring MVC 头像上传

在请求到的action类中判断请求是GET方式还是POST方式的方法如下:

String method = request.getMethod();
        if("GET".equals(method)){
            return "ssl/acc_photo_center";
        }

在请求到的action类中获取form表单中提交的文件对象方法

MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;   
 MultipartFile file = multiRequest.getFile("file"); //name

@RequestMapping(value = "...", method = {RequestMethod.POST, RequestMethod.GET})

假如在请求到达对应的action类中的方法前,请求的是get方式或者是post方式全部不会有问题,请求方式是哪种在方法中就会调用哪种方式的请求,假如method方式中只有POST方式请求时,在用户刷新地址栏时就会出现request get方式不支持,因为手动刷新url地址栏就等同于get方式请求。

猜你喜欢

转载自liuzhiqiang19890403.iteye.com/blog/2162533