봄 MVC 3을 사용하고 있습니다. 업로드 된 파일의 속성에 액세스하려고 시도했지만 다음 오류 메시지가 계속 표시됩니다. 게시 된 양식의 다른 입력란에는 액세스 할 수 있지만 업로드 된 파일에는 액세스 할 수 없습니다.봄 3에서 파일 업로드 MVC - Null 포인터 예외
nullhandleForm - Failed to convert property value of type 'java.lang.String' to required type
'org.springframework.web.multipart.commons.CommonsMultipartFile' for property 'file';
nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.commons.CommonsMultipartFile]
for property 'file': no matching editors or conversion strategy found
HTML/JSP 파일
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<p>${Response}</p>
<h1>Upload Songs</h1>
<table>
<form:form action="" commandName="handleForm">
<tr>
<td>Song Name :</td>
<td><form:input path="songName"/></td>
</tr>
<tr>
<td>Artist Name :</td>
<td><form:input path="artistName"/></td>
</tr>
<tr>
<td>Gendre :</td>
<td><form:input path="gendre"/></td>
</tr>
<tr>
<td>description :</td>
<td><form:textarea path="description"/></td>
</tr>
<tr>
<td>Browse File :</td>
<td><form:input type="file" path="file" /></td>
</tr>
<tr>
<td colspan="2" style="text-align: center"><input type="submit" value="submit" /></td>
</tr>
</form:form>
</table>
</body>
양식 handlerclass
public class HandleForm {
private String songName;
private String artistName;
private String gendre;
private String description;
private CommonsMultipartFile file;
public CommonsMultipartFile getFile() {
return file;
}
public void setFile(CommonsMultipartFile file) {
this.file = file;
}
public String getArtistName() {
return artistName;
}
public void setArtistName(String artistName) {
this.artistName = artistName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getGendre() {
return gendre;
}
public void setGendre(String gendre) {
this.gendre = gendre;
}
public String getSongName() {
return songName;
}
public void setSongName(String songName) {
this.songName = songName;
}
}
컨트롤러
@Controller
public class AdminController{
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String showAdmin(){
return "admin/index";
}
@RequestMapping(value = "/admin/upload-songs", method = RequestMethod.GET)
public String showContacts(Model model) {
model.addAttribute(new HandleForm());
return "/admin/upload";
}
@RequestMapping(value = "/admin/upload-songs", method = RequestMethod.POST)
public String doForm(@ModelAttribute(value = "handleForm") HandleForm handleForm, BindingResult result, Model model){
if(result.hasErrors()){
String stringList = null;
List<FieldError> errors = result.getFieldErrors();
for (FieldError error : errors) {
stringList += error.getObjectName() + " - " + error.getDefaultMessage() + "\n";
}
model.addAttribute("Response", stringList);
//model.addAttribute("songname", handleForm.getSongName()); works fine
//model.addAttribute("filename", handleForm.getFile().getOriginalFilename()); throws an error..?
}
return "/admin/upload";
}
}
도움을 주시면 감사하겠습니다. 미리 감사드립니다