のライブラリが必要です。
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Logger log = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); try { //URLより保存場所の絶対パスを入手 ServletContext sc = getServletContext(); String path = sc.getRealPath("/WEB-INF"); log.info("filepath:" + path); File fileDir = new File(path); if (!ServletFileUpload.isMultipartContent(new ServletRequestContext(request))) { throw (new Exception("Not FileUpload Request")); } ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); List<fileitem> list = upload.parseRequest(request); for (Iterator<fileitem> iter = list.iterator(); iter.hasNext();) { FileItem fItem = (FileItem) iter.next(); if (fItem.isFormField()) { continue; } String fileName = (new File(fItem.getName())).getName(); File newFile = new File(fileDir, fileName); fItem.write(newFile); } log.info("アップロード終了"); } catch (Exception ex) { log.warning("アップロード処理異常終了"); } }
0 件のコメント:
コメントを投稿