List of usage examples for org.apache.commons.fileupload DiskFileUpload setSizeThreshold
public void setSizeThreshold(int sizeThreshold)
From source file:org.apache.struts.upload.CommonsMultipartRequestHandler.java
/** * <p> Parses the input stream and partitions the parsed items into a set * of form fields and a set of file items. In the process, the parsed * items are translated from Commons FileUpload <code>FileItem</code> * instances to Struts <code>FormFile</code> instances. </p> * * @param request The multipart request to be processed. * @throws ServletException if an unrecoverable error occurs. *///from www .j a v a2 s .c o m public void handleRequest(HttpServletRequest request) throws ServletException { // Get the app config for the current request. ModuleConfig ac = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY); // Create and configure a DIskFileUpload instance. DiskFileUpload upload = new DiskFileUpload(); // The following line is to support an "EncodingFilter" // see http://issues.apache.org/bugzilla/show_bug.cgi?id=23255 upload.setHeaderEncoding(request.getCharacterEncoding()); // Set the maximum size before a FileUploadException will be thrown. upload.setSizeMax(getSizeMax(ac)); // Set the maximum size that will be stored in memory. upload.setSizeThreshold((int) getSizeThreshold(ac)); // Set the the location for saving data on disk. upload.setRepositoryPath(getRepositoryPath(ac)); // Create the hash tables to be populated. elementsText = new Hashtable(); elementsFile = new Hashtable(); elementsAll = new Hashtable(); // Parse the request into file items. List items = null; try { items = upload.parseRequest(request); } catch (DiskFileUpload.SizeLimitExceededException e) { // Special handling for uploads that are too big. request.setAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED, Boolean.TRUE); return; } catch (FileUploadException e) { log.error("Failed to parse multipart request", e); throw new ServletException(e); } // Partition the items into form fields and files. Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { addTextParameter(request, item); } else { addFileParameter(item); } } }
From source file:org.araneaframework.servlet.filter.StandardServletFileUploadFilterService.java
protected void action(Path path, InputData input, OutputData output) throws Exception { HttpServletRequest request = ((ServletInputData) input).getRequest(); if (FileUpload.isMultipartContent(request)) { Map fileItems = new HashMap(); Map parameterLists = new HashMap(); // Create a new file upload handler DiskFileUpload upload = new DiskFileUpload(); if (useRequestEncoding) upload.setHeaderEncoding(request.getCharacterEncoding()); else if (multipartEncoding != null) upload.setHeaderEncoding(multipartEncoding); // Set upload parameters if (maximumCachedSize != null) upload.setSizeThreshold(maximumCachedSize.intValue()); if (maximumSize != null) upload.setSizeMax(maximumSize.longValue()); if (tempDirectory != null) upload.setRepositoryPath(tempDirectory); // Parse the request List items = upload.parseRequest(request); // Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { fileItems.put(item.getFieldName(), item); } else { List parameterValues = (List) parameterLists.get(item.getFieldName()); if (parameterValues == null) { parameterValues = new ArrayList(); parameterLists.put(item.getFieldName(), parameterValues); }// w ww.ja va2 s .c o m parameterValues.add(item.getString()); } } log.debug("Parsed multipart request, found '" + fileItems.size() + "' file items and '" + parameterLists.size() + "' request parameters"); output.extend(ServletFileUploadInputExtension.class, new StandardServletFileUploadInputExtension(fileItems)); request = new MultipartWrapper(request, parameterLists); ((ServletOverridableInputData) input).setRequest(request); } super.action(path, input, output); }
From source file:org.bootchart.servlet.RenderServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { File logTmpFile = null;//w w w.j a v a 2 s .c o m try { DiskFileUpload fu = new DiskFileUpload(); // maximum size before a FileUploadException will be thrown fu.setSizeMax(32 * 1024 * 1024); fu.setSizeThreshold(4 * 1024 * 1024); fu.setRepositoryPath(TEMP_DIR); String format = "png"; List fileItems = fu.parseRequest(request); File tmpFile = File.createTempFile("file.", ".tmp"); String tmpName = tmpFile.getName().substring(5, tmpFile.getName().length() - 4); tmpFile.delete(); for (Iterator i = fileItems.iterator(); i.hasNext();) { FileItem fi = (FileItem) i.next(); String name = fi.getName(); if (name == null || name.length() == 0) { if ("format".equals(fi.getFieldName())) { format = fi.getString(); } continue; } if (name.indexOf("bootchart") != -1) { String suffix = ""; if (name.endsWith(".tar.gz")) { suffix = ".tar.gz"; } else { suffix = name.substring(name.lastIndexOf('.')); } logTmpFile = new File(TEMP_DIR, "bootchart." + tmpName + suffix); fi.write(logTmpFile); } } if (logTmpFile == null || !logTmpFile.exists()) { writeError(response, LOG_FORMAT_ERROR, null); log.severe("No log tarball provided"); return; } // Render PNG by default if (format == null) { format = "png"; } boolean prune = true; new File(TEMP_DIR + "/images").mkdirs(); String tmpImgFileName = TEMP_DIR + "/images/" + "bootchart." + tmpName; File tmpImgFile = null; try { tmpImgFileName = Main.render(logTmpFile, format, prune, tmpImgFileName); tmpImgFile = new File(tmpImgFileName); FileInputStream fis = new FileInputStream(tmpImgFileName); OutputStream os = response.getOutputStream(); String contentType = "application/octet-stream"; String suffix = ""; if ("png".equals(format)) { contentType = "image/png"; suffix = new PNGRenderer().getFileSuffix(); } else if ("svg".equals(format)) { contentType = "image/svg+xml"; suffix = new SVGRenderer().getFileSuffix(); } else if ("eps".equals(format)) { contentType = "image/eps"; suffix = new EPSRenderer().getFileSuffix(); } response.setContentType(contentType); response.setHeader("Content-disposition", "attachment; filename=bootchart." + suffix); byte[] buff = new byte[4096]; while (true) { int read = fis.read(buff); if (read < 0) { break; } os.write(buff, 0, read); os.flush(); } fis.close(); } finally { if (tmpImgFile != null && !tmpImgFile.delete()) { tmpImgFile.deleteOnExit(); } } } catch (Exception e) { writeError(response, null, e); log.log(Level.SEVERE, "", e); } if (logTmpFile != null && !logTmpFile.delete()) { logTmpFile.deleteOnExit(); } }
From source file:org.hdiv.config.multipart.StrutsMultipartConfig.java
/** * Parses the input stream and partitions the parsed items into a set of form fields and a set of file items. * //from w ww. ja v a 2 s .c o m * @param request * The multipart request wrapper. * @param servletContext * Our ServletContext object * @return multipart processed request * @throws HdivMultipartException * if an unrecoverable error occurs. */ public HttpServletRequest handleMultipartRequest(RequestWrapper request, ServletContext servletContext) throws HdivMultipartException { DiskFileUpload upload = new DiskFileUpload(); upload.setHeaderEncoding(request.getCharacterEncoding()); // Set the maximum size before a FileUploadException will be thrown. upload.setSizeMax(getSizeMax()); // Set the maximum size that will be stored in memory. upload.setSizeThreshold((int) getSizeThreshold()); // Set the the location for saving data on disk. upload.setRepositoryPath(getRepositoryPath(servletContext)); List<FileItem> items = null; try { items = upload.parseRequest(request); } catch (DiskFileUpload.SizeLimitExceededException e) { if (log.isErrorEnabled()) { log.error("Size limit exceeded exception"); } // Special handling for uploads that are too big. throw new HdivMultipartException(e); } catch (FileUploadException e) { if (log.isErrorEnabled()) { log.error("Failed to parse multipart request", e); } throw new HdivMultipartException(e); } // Process the uploaded items Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (item.isFormField()) { this.addTextParameter(request, item); } else { this.addFileParameter(request, item); } } return request; }
From source file:org.liquidsite.core.web.MultiPartRequest.java
/** * Parses the incoming multi-part HTTP request. * * @param request the HTTP request * * @throws FileUploadException if the request couldn't be parsed * correctly//from w w w .jav a 2 s . c o m */ private void parse(HttpServletRequest request) throws FileUploadException { DiskFileUpload parser = new DiskFileUpload(); List list; FileItem item; String value; // Create multi-part parser parser.setRepositoryPath(uploadDir); parser.setSizeMax(uploadSize); parser.setSizeThreshold(4096); // Parse request list = parser.parseRequest(request); for (int i = 0; i < list.size(); i++) { item = (FileItem) list.get(i); if (item.isFormField()) { try { value = item.getString("UTF-8"); } catch (UnsupportedEncodingException ignore) { value = item.getString(); } parameters.put(item.getFieldName(), value); } else { files.put(item.getFieldName(), new MultiPartFile(item)); } } }
From source file:org.talend.mdm.webapp.browserecords.server.servlet.UploadData.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); //$NON-NLS-1$ response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$ if (!FileUploadBase.isMultipartContent(request)) { throw new ServletException(MESSAGES.getMessage("error_upload")); //$NON-NLS-1$ }/*from w w w.ja v a 2 s . c o m*/ // Create a new file upload handler DiskFileUpload upload = new DiskFileUpload(); // Set upload parameters upload.setSizeThreshold(0); upload.setSizeMax(-1); PrintWriter writer = response.getWriter(); try { String concept = null; String seperator = null; String textDelimiter = "\""; //$NON-NLS-1$ String language = "en"; //$NON-NLS-1$ Locale locale = null; String encoding = "utf-8";//$NON-NLS-1$ Map<String, Boolean> headerVisibleMap = new LinkedHashMap<String, Boolean>(); String headerString = null; String mandatoryField = null; List<String> inheritanceNodePathList = null; boolean headersOnFirstLine = false; boolean isPartialUpdate = false; String multipleValueSeparator = null; String fileType = null; File file = null; // Parse the request List<FileItem> items = upload.parseRequest(request); // Process the uploaded items Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { // FIXME: should handle more than files in parts e.g. text passed as parameter FileItem item = iter.next(); if (item.isFormField()) { // we are not expecting any field just (one) file(s) String name = item.getFieldName(); LOG.debug("doPost() Field: '" + name + "' - value:'" + item.getString() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (name.equals("concept")) { //$NON-NLS-1$ concept = item.getString(); } else if (name.equals("sep")) { //$NON-NLS-1$ seperator = item.getString(); } else if (name.equals("delimiter")) { //$NON-NLS-1$ textDelimiter = item.getString(); } else if (name.equals("language")) { //$NON-NLS-1$ locale = new Locale(item.getString()); } else if (name.equals("encodings")) { //$NON-NLS-1$ encoding = item.getString(); } else if (name.equals("header")) { //$NON-NLS-1$ headerString = item.getString(); List<String> headerItemList = org.talend.mdm.webapp.base.shared.util.CommonUtil .convertStrigToList(headerString, Constants.FILE_EXPORT_IMPORT_SEPARATOR); if (headerItemList != null) { for (String headerItem : headerItemList) { String[] headerItemArray = headerItem.split(Constants.HEADER_VISIBILITY_SEPARATOR); headerVisibleMap.put(headerItemArray[0], Boolean.valueOf(headerItemArray[1])); } } } else if (name.equals("mandatoryField")) { //$NON-NLS-1$ mandatoryField = item.getString(); } else if (name.equals("inheritanceNodePath")) { //$NON-NLS-1$ inheritanceNodePathList = org.talend.mdm.webapp.base.shared.util.CommonUtil .convertStrigToList(item.getString(), Constants.FILE_EXPORT_IMPORT_SEPARATOR); } else if (name.equals("headersOnFirstLine")) { //$NON-NLS-1$ headersOnFirstLine = "on".equals(item.getString()); //$NON-NLS-1$ } else if (name.equals("multipleValueSeparator")) { //$NON-NLS-1$ multipleValueSeparator = item.getString(); } else if (name.equals("isPartialUpdate")) { //$NON-NLS-1$ isPartialUpdate = "on".equals(item.getString()); //$NON-NLS-1$ } } else { fileType = FileUtil.getFileType(item.getName()); file = File.createTempFile("upload", "tmp");//$NON-NLS-1$ //$NON-NLS-2$ LOG.debug("doPost() data uploaded in " + file.getAbsolutePath()); //$NON-NLS-1$ file.deleteOnExit(); item.write(file); } // if field } // while item if (!UploadUtil.isViewableXpathValid(headerVisibleMap.keySet(), concept)) { throw new UploadException(MESSAGES.getMessage(locale, "error_invaild_field", concept)); //$NON-NLS-1$ } Set<String> mandatorySet = UploadUtil.chechMandatoryField( org.talend.mdm.webapp.base.shared.util.CommonUtil.unescape(mandatoryField), headerVisibleMap.keySet()); if (mandatorySet.size() > 0) { throw new UploadException(MESSAGES.getMessage(locale, "error_missing_mandatory_field")); //$NON-NLS-1$ } UploadService service = generateUploadService(concept, fileType, isPartialUpdate, headersOnFirstLine, headerVisibleMap, inheritanceNodePathList, multipleValueSeparator, seperator, encoding, textDelimiter.charAt(0), language); List<WSPutItemWithReport> wsPutItemWithReportList = service.readUploadFile(file); putDocument(new WSPutItemWithReportArray( wsPutItemWithReportList.toArray(new WSPutItemWithReport[wsPutItemWithReportList.size()])), concept); writer.print(Constants.IMPORT_SUCCESS); } catch (Exception exception) { LOG.error(exception.getMessage(), exception); writer.print(extractErrorMessage(exception.getMessage())); } finally { writer.close(); } }
From source file:ro.finsiel.eunis.admin.EUNISUploadServlet.java
/** * Overrides public method doPost of javax.servlet.http.HttpServlet. * * @param request/*from w ww . ja v a 2s .c om*/ * Request object * @param response * Response object. */ public void doPost(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(false); sessionManager = (SessionManager) session.getAttribute("SessionManager"); // Initialise the default settings try { BASE_DIR = getServletContext().getInitParameter(Constants.APP_HOME_INIT_PARAM); TEMP_DIR = BASE_DIR + getServletContext().getInitParameter("TEMP_DIR"); } catch (Exception ex) { ex.printStackTrace(); } List items = new ArrayList(); boolean isMultipart = FileUpload.isMultipartContent(request); DiskFileUpload upload = new DiskFileUpload(); upload.setSizeThreshold(MAX_MEM_TRESHOLD); upload.setSizeMax(MAX_FILE_SIZE); upload.setRepositoryPath(TEMP_DIR); try { items = upload.parseRequest(request); } catch (FileUploadException ex) { ex.printStackTrace(); try { response.sendRedirect("related-reports-error.jsp?status=Error while interpreting request"); } catch (IOException _ex) { _ex.printStackTrace(); } } // If it's a multi-part content then it's an upload. So we process it. if (isMultipart) { int uploadType = -1; String description = ""; // Description of the uploaded document (used only for UPLOAD_TYPE_FILE) // Process the uploaded items for (int i = 0; i < items.size(); i++) { FileItem item = (FileItem) items.get(i); if (item.isFormField()) { // FORM FIELD String fieldName = item.getFieldName(); String fieldValue = item.getString(); if (null != fieldName && fieldName.equals("uploadType")) { if (null != fieldValue && fieldValue.equalsIgnoreCase("file")) { uploadType = UPLOAD_TYPE_FILE; } if (null != fieldValue && fieldValue.equalsIgnoreCase("picture")) { uploadType = UPLOAD_TYPE_PICTURE; } } // Id object if (null != fieldName && fieldName.equalsIgnoreCase("idobject")) { natureObjectInfo.idObject = fieldValue; } // Description if (null != fieldName && fieldName.equalsIgnoreCase("description")) { natureObjectInfo.description = fieldValue; description = fieldValue; } // Nature object type if (null != fieldName && fieldName.equalsIgnoreCase("natureobjecttype")) { natureObjectInfo.natureObjectType = fieldValue; } } } if (uploadType == UPLOAD_TYPE_FILE) { String message = ""; if (sessionManager.isAuthenticated() && sessionManager.isUpload_reports_RIGHT()) { try { uploadDocument(items, message, sessionManager.getUsername(), description); response.sendRedirect("related-reports-upload.jsp?message=" + message); } catch (IOException ex) { // Thrown by sendRedirect ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); try { String errorURL = "related-reports-error.jsp?status=" + ex.getMessage(); response.sendRedirect(errorURL); // location is a dummy param } catch (IOException ioex) { ioex.printStackTrace(); } } } else { message = "You must be logged in and have the 'upload files' "; message += "right in order to use this feature. Upload is not possible."; try { response.sendRedirect("related-reports-error.jsp?status=" + message); } catch (Exception ex) { ex.printStackTrace(); } } } if (uploadType == UPLOAD_TYPE_PICTURE) { if (sessionManager.isAuthenticated() && sessionManager.isUpload_pictures_RIGHT()) { try { uploadPicture(items); String redirectStr = "pictures-upload.jsp?operation=upload"; redirectStr += "&idobject=" + natureObjectInfo.idObject; redirectStr += "&natureobjecttype=" + natureObjectInfo.natureObjectType; redirectStr += "&filename=" + natureObjectInfo.filename; redirectStr += "&message=Picture successfully loaded."; response.sendRedirect(redirectStr); } catch (IOException ex) { // Thrown by sendRedirect ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); try { response.sendRedirect( "related-reports-error.jsp?status=An error ocurred during picture upload. " + ex.getMessage()); } catch (IOException ioex) { ioex.printStackTrace(); } } } else { try { response.sendRedirect( "related-reports-error.jsp?status=You do not have the proper rights. Upload is not possible."); } catch (IOException ex) { ex.printStackTrace(); } } } } }
From source file:sos.settings.SOSSettingsDialog.java
private void checkRequest() throws Exception { this.debug(3, "checkRequest"); this.settings.sources.put(this.settings.source, this.dialogApplicationsTitle); this.settings.application = ""; this.settings.section = ""; this.settings.entry = ""; this.inputQuery = ""; this.inputExport = ""; this.inputImport = ""; this.importOriginalFileName = ""; // Daten aus fileUpload LinkedHashMap requestMultipart = new LinkedHashMap(); if (this.request != null) { ///////////////////////////////////////////////////////// String contentType = this.request.getHeader("Content-type"); if (contentType != null && contentType.startsWith("multipart/")) { // ob Import try { DiskFileUpload upload = new DiskFileUpload(); upload.setSizeMax(this.importMaxSize); upload.setSizeThreshold(0); // nicht im Memory sondern als // Datei speichern List items = upload.parseRequest(this.request); Iterator iter = items.iterator(); while (iter.hasNext()) { //FileItem item = (FileItem) iter.next(); DefaultFileItem item = (DefaultFileItem) iter.next(); if (item.isFormField()) { requestMultipart.put(item.getFieldName(), item.getString()); this.request.setAttribute(item.getFieldName(), item.getString()); } else { // aus upload if (item.getName() != null && !item.getName().equals("")) { //requestMultipart.put(item.getFieldName(),item.getStoreLocation()); requestMultipart.put(item.getFieldName(), item.getStoreLocation().getAbsolutePath()); this.request.setAttribute(item.getFieldName(), item.getStoreLocation().getAbsolutePath()); this.importOriginalFileName = item.getName(); } else { requestMultipart.put(item.getFieldName(), ""); this.request.setAttribute(item.getFieldName(), ""); }/*from w w w . j a va 2 s . c om*/ } } } catch (FileUploadException e) { this.setError(e.getMessage(), SOSClassUtil.getMethodName()); } } // MULTIPART Form ///////////////////////////////////////////////////////// if (this.getRequestValue("application") != null) { this.settings.application = this.getRequestValue("application"); } if (this.getRequestValue("section") != null) { this.settings.section = this.getRequestValue("section"); } if (this.getRequestValue("entry") != null) { this.settings.entry = this.getRequestValue("entry"); } if (this.getRequestValue("application_type") != null) { try { this.applicationType = Integer.parseInt(this.getRequestValue("application_type")); } catch (Exception e) { this.applicationType = 0; } } if (this.getRequestValue("section_type") != null) { try { this.sectionType = Integer.parseInt(this.getRequestValue("section_type")); } catch (Exception e) { this.sectionType = 0; } } if (this.getRequestValue("action") != null) { this.action = this.getRequestValue("action"); } if (this.getRequestValue("range") != null) { this.range = this.getRequestValue("range"); } if (this.getRequestValue("item") != null) { this.item = this.getRequestValue("item"); } if ((this.getRequestValue("btn_store.x") != null) && (this.getRequestValue("btn_store.y") != null)) { this.action = "store"; } else if ((this.getRequestValue("btn_insert.x") != null) && (this.getRequestValue("btn_insert.y") != null)) { this.action = "insert"; } else if ((this.getRequestValue("btn_delete.x") != null) && (this.getRequestValue("btn_delete.y") != null)) { this.action = "delete"; } else if ((this.getRequestValue("btn_schema.x") != null) && (this.getRequestValue("btn_schema.y") != null)) { this.action = "schema"; } else if ((this.getRequestValue("btn_duplicate.x") != null) && (this.getRequestValue("btn_duplicate.y") != null)) { this.action = "duplicate"; this.range = "entries"; } else if ((this.getRequestValue("btn_cancel.x") != null) && (this.getRequestValue("btn_cancel.y") != null)) { this.action = "show"; if (this.range.equals("application")) { this.range = "applications"; } else if (this.range.equals("section")) { this.range = "sections"; } else { this.range = this.range.equals("list") ? "sections" : "entries"; } } else if ((this.getRequestValue("btn_query.x") != null) && (this.getRequestValue("btn_query.y") != null)) { this.action = "query"; this.range = "entries"; if (this.getRequestValue("query_select_range") != null && this.getRequestValue("query_select_range").equals("2")) { this.item = "replace"; } } else if ((this.getRequestValue("btn_export.x") != null) && (this.getRequestValue("btn_export.y") != null)) { this.action = "export"; this.range = "entries"; } else if ((this.getRequestValue("btn_import.x") != null) && (this.getRequestValue("btn_import.y") != null)) { this.action = "import"; this.range = "entries"; } else if ((this.getRequestValue("btn_clipboard_copy.x") != null) && (this.getRequestValue("btn_clipboard_copy.y") != null)) { if (this.getRequestValue("last_action") != null) { this.action = this.getRequestValue("last_action"); } else { this.action = "show"; } this.clipboardAction = "copy"; } else if ((this.getRequestValue("btn_clipboard_paste.x") != null) && (this.getRequestValue("btn_clipboard_paste.y") != null)) { if (this.getRequestValue("last_action") != null) { this.action = this.getRequestValue("last_action"); } else { this.action = "show"; } this.clipboardAction = "paste"; } else if ((this.getRequestValue("btn_import_file.x") != null) && (this.getRequestValue("btn_import_file.y") != null)) { this.action = ((this.getRequestValue("last_action") != null) && this.getRequestValue("last_action").equals("new")) ? "insert" : "store"; this.range = "entry"; this.item = "upload"; } if (this.getRequestValue("input_query") != null) { this.inputQuery = this.getRequestValue("input_query"); } if (this.getRequestValue("input_query_replace") != null) { this.replaceQuery = this.getRequestValue("input_query_replace"); } if (this.getRequestValue("input_export") != null) { this.inputExport = this.getRequestValue("input_export"); } if (this.getRequestValue("export_documentation") != null) { this.exportDocumentation = 1; } if (this.getRequestValue("input_import") != null) { this.inputImport = this.getRequestValue("input_import"); } } if (this.applicationName.equals("")) { this.applicationName = this.settings.application; } if (this.enableShowDevelopmentData) { this.showDevelopmentData(requestMultipart); } }
From source file:thinwire.render.web.WebServlet.java
private void handleUserUpload(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { HttpSession httpSession = request.getSession(); ApplicationHolder holder = (ApplicationHolder) httpSession.getAttribute("instance"); if (holder.app != null) { try {/* w w w. j ava2s . co m*/ DiskFileUpload upload = new DiskFileUpload(); upload.setSizeThreshold(1000000); upload.setSizeMax(-1); upload.setRepositoryPath("C:\\"); List<FileItem> items = upload.parseRequest(request); if (items.size() > 0) { FileChooser.FileInfo f = null; synchronized (holder.app.fileList) { for (FileItem fi : items) { if (!fi.isFormField()) { f = new FileChooser.FileInfo(fi.getName(), fi.getInputStream()); holder.app.fileList[0] = f; } } holder.app.fileList.notify(); } } } catch (FileUploadException e) { log.log(Level.SEVERE, null, e); } } response.sendRedirect("?_twr_=FileUploadPage.html"); }