spring上传
注冊并上傳頁面<form action="upload" method="post" enctype="multipart/form-data">賬戶:<input type="text" name="username"/><br/>密碼:<input type="password" name="pwd"/><br/>文件:<input type="file" name="mf"/><br/><input type="submit" value="注冊"/></form>
spring-mvc配置文件,增加如下代碼: <bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><!-- one of the properties available; the maximum file size in bytes --><property name="maxUploadSize" value="10000000"/>
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
控制器代碼如下:
//3.上傳案例@RequestMapping("/upload")public String register(User u,Model model,@RequestParam("mf") MultipartFile mf){ System.out.println("name="+u.getUsername()+ ",pwd="+u.getPwd());model.addAttribute("msg", "注冊成功");userList.add(u);try { FileUtils.copyInputStreamToFile(mf.getInputStream(), new File("E:/"+mf.getOriginalFilename()));} catch (IOException e) {e.printStackTrace();} System.out.println(mf.getOriginalFilename()+","+mf.getSize());return "login";}spring-mvc配置文件,增加如下代碼: <bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><!-- one of the properties available; the maximum file size in bytes --><property name="maxUploadSize" value="10000000"/>
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
- 上一篇: spring mvc 模拟数据库实现注册
- 下一篇: spring json