2010年3月10日星期三

[note]Spring MultipartFile类解决文件上传问题

使用MultipartFile类解决文件的上传十分方便,代码如下:

        @RequestMapping(value = "/member/spaceBackground.do", method = RequestMethod.POST)
public void processSetupBackground(Model model, HttpServletResponse resp, HttpServletRequest req, @RequestParam("fileupload") MultipartFile fileupload) {
try {
String logoName = "logonai.gif";
String filePath = ProjectEnv.getWebappPath() + "/images/";
FileTools.input2File(filePath, fileupload.getInputStream(), logoName, true);  //将上传的文件用input流的方式传到文件logonai.gif中
PrintWriter out = resp.getWriter();
out.print("true");
out.close();
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}

没有评论: