ognl源码包值得用一用
很好的xwork的资源包public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DiskFileItemFactory factory = new DiskFileItemFactory(); String path = request.getRealPath("/upload"); factory.setRepository(new File(path)); // 1mb factory.setSizeThreshold(1024 * 1024); // 实现文件上传的核心 ServletFileUpload upload = new ServletFileUpload(factory); try { List list = upload.parseRequest(request); for (FileItem item : list) { if (ite m.isFormField()) { String name = item.getFieldName(); String value = item.getString("GBK"); System.out.println("name = " + name); request.setAttribute(name, value); } else { // 文件名的处理 String name = item.getFieldName(); String value = item.getString("GBK"); int start = value.lastIndexOf("\\"); String fileName = value.substring(start, start + 1); request.setAttribute(name, fileName); OutputStream os = new FileOutputStream(new File(fileName)); InputStream in = item.getInputStream(); // 写入内存缓冲区 byte[] buf = new byte[1024]; int length = 0; while ((length = in.read(buf)) > 0) { os.write(buf, 0, length); } os.close(); in.close(); } } } catch (Exception e) { e.printStackTrace(); } request.getRequestDispatcher("upload/result3.jsp").forward(request, response); m.isFormField()) { String name = item.getFieldName(); String value = item.getString("GBK"); System.out.println("name = " + name); request.setAttribute(name, value); } else { // 文件名的处理 String name = item.getFieldName(); String value = item.getString("GBK"); int start = value.lastIndexOf("\\"); String fileName = value.substring(start, start + 1); request.setAttribute(name, fileName); OutputStream os = new FileOutputStream(new File(fileName)); InputStream in = item.getInputStream(); // 写入内存缓冲区 byte[] buf = new byte[1024]; int length = 0; while ((length = in.read(buf)) > 0) { os.write(buf, 0, length); } os.close(); in.close(); } } } catch (Exception e) { e.printStackTrace(); } request.getRequestDispatcher("upload/result3.jsp").forward(request, response);
暂无评论