首页 > 代码库 > springMVC之文件上传
springMVC之文件上传
1. 引入Jar包
commons-fileupload-1.2.2.jar
commons-io-2.1.jar
2.user-servlet.xml中配置文件上传
<!-- 配置文件上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value=http://www.mamicode.com/"5000000">>3. UserController.java@Controller @RequestMapping("/user") public class UserController { // 使用map模拟数据库 private Map<String, User> userMap = new HashMap<String, User>(); public UserController() { userMap.put("zhangsan", new User("zhangsan", "123")); userMap.put("lishimin", new User("lishimin", "456")); } // 文件上传 // 访问方法: http://localhost/springmvc_user/upload.jsp @RequestMapping(value=http://www.mamicode.com/"/upload",method=RequestMethod.POST)>4. upload.jsp<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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>文件上传</title> </head> <body> <form method="post" action="user/upload" enctype="multipart/form-data"> Attach:<br/> <input type="file" name="attachs"/><br/> <input type="file" name="attachs"/><br/> <input type="file" name="attachs"/><br/> <input type="submit" value=http://www.mamicode.com/"上传文件"/>>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。