哈师大附中陈广庆

全部分类 | 读书与思考 | 做人 | 做事 | 享受生活
« 北京欢迎你(现场、mv、声音版) | 主页 | 好电影《功夫熊猫》 »

20080623 Monday 2008年06月23日

annotation驱动的spring mvc文件上传 jsp文件:
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form  method="post" action="uploadfile.do" enctype ="multipart/form-data">
            <input type="file"  name="file"/>
            <input type="submit" value="upload"/>
        </form>
    </body>
</html>

controller:

@Controller
public class FileUploadController {
    @RequestMapping("/editor/preuploadfile.do")
    public String uploadrequest(){
        return "/editor/uploadfile";
    }
    @RequestMapping("/editor/uploadfile.do")
    public String processSubmit(@RequestParam("file") MultipartFile mfile ) throws IOException{
        File file = new File(mfile.getOriginalFilename());
        mfile.transferTo(new File("D:\\Temp\\"+file.getName()));
        return "editor/uploadfinish";
    }
}

xml配置项:

<!-- MultipartResolver for parsing file uploads, implementation for Commons FileUpload -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

简单得难以置信!
发表于 chsan ( 2008年06月23日, 02:42:23 PM CST ) Permalink

评论:

发表一条评论:

该日志评论功能被禁用了。