1. 首页
  2. 编程语言
  3. Java
  4. ognl源码包值得用一用

ognl源码包值得用一用

上传者: 2019-01-02 21:37:14上传 EXE文件 2.75MB 热度 42次
很好的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);
用户评论