<html> <head> <title>excel导入到数据库</title> </head> <body> <h3>excel导入到数据库:</h3> 选择一个文件进行上传: <br /> <form action="UploadFile_view.jsp?action=submit" method="post" enctype="multipart/form-data"> <input type="file" name="file" size="50" /> <br /> <input type="submit" value="上传" /> </form> <% if (request.getParameter("action") != null) { if (request.getParameter("action").equals("submit")) { int maxFileSize = 5000 * 1024; int maxMemSize = 5000 * 1024; ServletContext context = pageContext.getServletContext(); String filePath = context.getInitParameter("file-upload"); String contentType = request.getContentType(); if ((contentType.indexOf("multipart/form-data") >= 0)) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(maxMemSize); factory.setRepository(new File("c:\\temp")); ServletFileUpload upload = new ServletFileUpload( factory); upload.setSizeMax(maxFileSize); List fileItems = upload.parseRequest(request); } } } %> </body> </html>
就是到这里fileItems就为空了
<html> <head> <title>excel导入到数据库</title> </head> <body> <h3>excel导入到数据库:</h3> 选择一个文件进行上传: <br /> <form action="UploadFile_view.jsp?action=submit" method="post" enctype="multipart/form-data"> <input type="file" name="file" size="50" /> <br /> <input type="submit" value="上传" /> </form> <% if (request.getParameter("action") != null) { if (request.getParameter("action").equals("submit")) { int maxFileSize = 5000 * 1024; int maxMemSize = 5000 * 1024; ServletContext context = pageContext.getServletContext(); String filePath = context.getInitParameter("file-upload"); String contentType = request.getContentType(); if ((contentType.indexOf("multipart/form-data") >= 0)) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(maxMemSize); factory.setRepository(new File("c:\\temp")); ServletFileUpload upload = new ServletFileUpload( factory); upload.setSizeMax(maxFileSize); List fileItems = upload.parseRequest(request); } } } %> </body> </html>
就是到这里fileItems就为空了