发送图像文件时不支持

时间:2017-06-09 06:52:42

标签: jquery ajax jsp spring-mvc

我正在将Image文件发送到客户端,但我得到了Get不受支持,即使我在ajax调用和控制器中使用post请求。

以下是html和ajax代码

<form:form  commandName="receiptDetails" action="createReceiptConfig" method="POST" id="submitForm">

<div class="imgText col-xs-12 col-sm-12 col-md-12">
                                    <input type="file" class="form-control" path="logoLink" id="logoLink">
                                                </input></br></div>

ajax代码是

 $('#submitForm').submit(function(e) { 
 var frm = $('#submitForm');
e.preventDefault();
var customerDetailsRequired = $('#customerDetailsRequired').is(":checked");
var businessNameRequired = $('#businessNameRequired').is(":checked");
var logoLink = $('#logoLink').val();
var formData = new FormData();
formData.append('logoImage', $('#logoLink')[0].files[0]);
alert($('#logoLink')[0].files[0]);
$.ajax({
    type: frm.attr('method'),
    url: frm.attr('action'),
    data : "logoImage="+formData+"&logoRequired="+logo+"&businessNameRequired="+businessNameRequired+"&returnPolicy="+retplcyValue+"&_csrf="+$("meta[name='_csrf']").attr("content"),
    success: function(data){
         $(".transDetails").html(data);
        location.reload();
    },
    error:function(data){
    }
});
}); 

控制器代码

@RequestMapping(value = "createReceiptConfig", method = RequestMethod.POST)
public @ResponseBody ModelAndView createReceiptConfig(@AuthenticationPrincipal PNSolUser loggedUser,
                                    @RequestParam("businessNameRequired") boolean businessNameRequired,

                                    @RequestParam("logoRequired") boolean logoRequired,
                                    @RequestParam("logoImage")  MultipartFile logoimg,                                      
                                    @RequestParam("returnPolicy") String returnPolicy)throws JsonParseException, JsonMappingException, IOException, Exception{

当我发送没有图像时,所有参数都很顺利。

0 个答案:

没有答案