增加依赖jar包
commons-fileupload commons-fileupload 1.3.1
修改springmvc.xml配置文件,添加
controller代码
package com.test.controller;import java.io.IOException;import java.util.List;import javax.annotation.Resource;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.multipart.MultipartFile;import org.springframework.web.servlet.ModelAndView;import net.sf.json.JSONObject;@Controllerpublic class ServiceDBController { private static Log log = LogFactory.getLog(ServiceDBController.class); @RequestMapping(value="test.do") public void test(@RequestParam("myFile")MultipartFile myFile) { //处理文件 }}
表单