标签:控制 use user view cep order 类型 tab 等于
<!--配置文件类型解析器-->
<!--这里的id 名称不能修改,因为在中央控制器中有指定的名称-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--大小 约等于 10M 以kb为单位-->
<property name="maxUploadSize" value="10240000"/>
</bean>
<%--action前面的"/" 加上表示使用绝对路径,反之为相对路径--%>
<form action="/getFile.do" method="post" enctype="multipart/form-data">
美女图片:
<input type="file" name="imgCard"><br>
<input type="su">
</form>
@RequestMapping("getFile.do")
public ModelAndView getFile(HttpServletRequest request, @RequestParam("imgCard") MultipartFile multipartFile) throws IOException {
String name = request.getParameter("name");
System.out.println("name = " + name);
//得到文件的名称;
String originalFilename = multipartFile.getOriginalFilename();
//希望存储的目标地址
File file = new File("C:\\Users\\lyuweigh\\Desktop\\"+originalFilename);
multipartFile.transferTo(file);
ModelAndView mv = new ModelAndView();
mv.setViewName("index.jsp");
mv.addObject("demo", "ojbk");
return mv;
}
- MultipartFile ,用来存储对应上传的文件
- @RequestParam("xx") ,接受指定的name名称值
<form action="/getFiles.do" method="post" enctype="multipart/form-data">
<table border="1">
<tr>
<td>文件名称:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td colspan="2"><input type="file" name="imgCards"></td>
</tr>
<tr>
<td colspan="2"><input type="file" name="imgCards"></td>
</tr>
<tr>
<td colspan="2"><input type="file" name="imgCards"></td>
</tr>
<tr>
<td colspan="2"><input type="file" name="imgCards"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="提交"></td>
</tr>
</table>
</form>
@RequestMapping("getFiles.do")
public ModelAndView getFiles(HttpServletRequest request, @RequestParam("imgCards") CommonsMultipartFile[] files) throws IOException {
String name = request.getParameter("name");
System.out.println("name = " + name);
for (CommonsMultipartFile file : files) {
String originalFilename = file.getOriginalFilename();
file.transferTo(new File("C:\\Users\\lyuweigh\\Desktop\\"+originalFilename));
}
ModelAndView mv = new ModelAndView();
mv.setViewName("index.jsp");
mv.addObject("demo", "ojbks");
return mv;
}
标签:控制 use user view cep order 类型 tab 等于
原文地址:https://www.cnblogs.com/lyuweigh/p/10080095.html