我对servlet 3.0规范和Spring 3.2并不熟悉。我只是想通过从jsp中获取<input type="file">
的输入来读取excel文件。下面是我的控制器类。 request.getParts().size()
始终为0.当我在firebug中看到网络面板时,会将一些内容发送到服务器。
@Controller
@RequestMapping("/upload")
@MultipartConfig
public class FileUploadController {
@RequestMapping(value = "/file", method = RequestMethod.POST)
public ModelAndView readFileData(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
System.out.println(request.getParts().size());
Part filePart = request.getPart("datafile");
String filename = getFilename(filePart);
//the below two lines are dummy. ignore it
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
不知道我哪里弄错了。请帮助。感谢。