请关注“知了堂学习社区”,地址:http://www.zhiliaotang.com/portal.php
今天的学习了文件上传出现了:
Required CommonsMultipartFile parameter ‘file’ is not present
开始一直以为是@RequestParm(“file”)参数的传递问题:
public void singleFlieUpload(@RequestParam("file") CommonsMultipartFile commonsMultipartFile, HttpServletRequest request, HttpServletResponse response) {
...}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/ssm/upload/singlefileupload.do" method="post" enctype="multipart/form-data">
<input type="file" name="file"><input type="submit">
</form>
</body>
</html>
粘贴复制很多遍以后发现,还是不行,百度之后,得到灵感
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:maxUploadSize="5242880"
p:maxInMemorySize="4096"
p:defaultEncoding="UTF-8">
</bean>
配置文件中的id是不能随便更改的,必须是multipartResolver
以此记录!!