2017-11-27 2 views
0

私のフォームは他の一般的なフィールドと一緒に画像を送信できますが、フォーム内の画像を選択すると送信は成功しますが、春にファイルを選択せず​​にフォームを送信できませんでした

Type Status Report 

Message Required request part 'profilePicture' is not present 

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). 


Apache Tomcat/8.5.23  

私のJSPコードを参照してください:

@RequestMapping(value="/register", method=RequestMethod.POST) 
public String processRegistration(
     @RequestPart("profilePicture") byte[] profilePicture, 
     @Valid Spitter spitter, Errors errors) 
{ 
    System.out.println("SpitterController.processRegistration is called first time"); 
    if (errors.hasErrors()) 
    { 
     System.out.println("find errors"); 
     return "registerForm"; 
    } 
    System.out.println("SpitterController.processRegistration is called"); 
    System.out.println(spitter.toString()); 
    spitterRespository.saveSpitter(spitter); 

    return "redirect:/spitter/"+spitter.getId(); 
} 
:ここ

<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %> 
<sf:form method="POST" modelAttribute="spitter" enctype="multipart/form-data"> 
<sf:errors path="*" cssClass="error" element="div"></sf:errors><br/> 
<sf:label path="id" cssErrorClass="error">User ID:</sf:label> <sf:input path="id" cssErrorClass="error" /><sf:errors path="id" /> <br /> 
<sf:label path="firstName" cssErrorClass="error">First Name: </sf:label><sf:input path="firstName" cssErrorClass="error"/><sf:errors path="firstName" cssClass="error" /> <br/> 
<sf:label path="lastName" cssErrorClass="error">Last Name: </sf:label><sf:input path="lastName" cssErrorClass="error"/><sf:errors path="lastName" cssClass="error"/> <br/> 
<sf:label path="password" cssErrorClass="error">Password: </sf:label><sf:password path="password" cssErrorClass="error"/><sf:errors path="password" cssClass="error"/> <br/> 
<br /> 
<label>Profile Picture</label> 
<input type="file" name="profilePicture" 
     accept="image/jpeg,image/png,image/gif" /><br /> 
<input type="submit" value="Register" /> 
</sf:form> 

は私のコントローラメソッドである絵、提出は400エラーがスローされます

私はこの問題を解決する方法について考えていないし、その理由を知らない、誰かが私を助けることができますか?

答えて

関連する問題