springframework6(MVC)設(shè)置文件上傳
spring6已經(jīng)不集成commonsupload,所以配置時(shí)使用StandardServletMultipartResolver
web.xml
<multipart-config>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
spring配置文件
<bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver"></bean>
示例代碼:
@RequestMapping(value="/upload",method=RequestMethod.POST)
public String upload(@RequestParam MultipartFile file) {
if (!file.isEmpty())
{
System.out.println(file.getOriginalFilename());
}
return "hello";
}
HTML FORM:
<form action="/cmspring/hello/upload" method="post" enctype="multipart/form-data">
? <fieldset>
? ? <legend>Registration example</legend>
? ? <p>
? ? ? <input type="file" name="file" />
? ? </p>
? ? <p>
? ? ? <input type="submit" />
? ? </p>
? </fieldset>
</form>