I have tried to solve this problem for 3 days and still getting the same error. I am trying to make a register/login spring mvc app. But it throw the exception when clicked on register button. Please help me to get it resolved. Thanks.
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Failed to parse multipart servlet request
Exception
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request
............
Root Cause
java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided........
Here is the controller:
@Controller
@MultipartConfig
public class RegistrationController extends HttpServlet {
@Autowired
public EmployeeService employeeService;
@Controller
@MultipartConfig
public class RegistrationController extends HttpServlet{
@RequestMapping(value="/register", method=RequestMethod.GET)
public ModelAndView mav = new ModelAndView("register");
mav.addObject("employee", new Employee());
return mav;
}
@RequestMapping(value="/register", method=RequestMethod.POST)
public MOdelAndView addUser(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("employee") Employee employee, @RequestParam MultipartFile photo){
employeeService.register(employee, photo);
return new ModelAndView("register","msg","Employee registered successfully");
}
}
The register.jsp page:
<form:form id="regForm" modelAttribute="employee" action="registerProcess" method="post"
enctype='multipart/form-data'>
...........
<tr>
<td><form:label path="photo">Employee Photo</form:label></td>
<td><form:input type="file" path="photo" name="photo" id="photo" /></td>
</tr>
<tr>
<td></td>
<td><form:button class="btn btn-primary" id="register" name="register">Register</form:button></td>
</tr>
</table>
</form:form>
Also, I have provided this in web.xml
<filter>
<filter-name>MultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
And application.properties,
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
and in context.xml inside resources
<Context allowCasualMultipartParsing="true"></Context>
I have tried already given answers in stackoverflow and other sites, but no change in error. Sometimes it’s just threw 404.
user25599999 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.