日期:2014-05-16 浏览次数:20829 次
<form action="mlgb.shtml" enctype="multipart/form-data" method="post"> <input type="file" name="file"/> <input type="text" name="filename"/> <input type="submit"/> </form>
@RequestMapping(value = "documentationupload.shtml") public String documentationupload(HttpServletRequest request, HttpServletResponse res) throws Exception { DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload uploader = new ServletFileUpload(factory); List<FileItem> list = uploader.parseRequest(request); for (FileItem item : list) { if (item.isFormField()) { // 处理普通表单字段 String field = item.getFieldName();//这个是name String value = item.getString("UTF-8");//这个是name对应的值 //对数据进行逻辑处理 } else { //将文件保存到指定目录 String fileName = item.getName();//文件名称 String filepath = pathUtil.getWebRoot() + uploadpath + fileName; item.write(new File(filepath));//执行保存 } } return "/admin/documentation.jsp"; }