title: servlet file upload filename encoding
body: <p>I am using the Apache Commons Fileupload tools for standard file upload. My problem is that I cannot get the proper filename of uploaded files if they contain special characters (á, é, ú, etc.) They all get converted to ? signs.</p>
  
  <p>request.getCharacterEncoding() says UTF-8, but the bytes I get in the string fileItem.getName() are all the same for all my special characters.</p>
  
  <p>Can you help me what's wrong?</p>
  
  <p>(Some details: using Firefox 3.6.12, Weblogic 10.3 on Windows)</p>
  
  <p>This is my code snippet:</p>
  
  <pre><code> public CommandMsg(HttpServletRequest request) {
      Enumeration names = null;
      if (isMultipart(request)) {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        try {
          List uploadedItems = upload.parseRequest(request);
          Iterator i = uploadedItems.iterator();
          FileItem fileItem = null;
          while (i.hasNext()) {
            fileItem = (FileItem) i.next();
            if (fileItem.isFormField()) {
              // System.out.println("isFormField");
              setAttribute(fileItem.getFieldName(), fileItem.getString());
            } else {
              String enc = "utf-8";
              enc = request.getCharacterEncoding();
              String fileName = fileItem.getName();
              byte[] fnb = fileItem.getName().getBytes();
              byte[] fnb2 = null;
              try {
                  fnb2 = fileItem.getName().getBytes(enc);
                  String t1 = new String(fnb);
                  String t2 = new String(fnb2);
                  String t3 = new String(fnb, enc);
                  String t4 = new String(fnb2, enc);
              } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              }
              setAttribute(fileItem.getFieldName(), fileItem);
            }
          }
        } catch (FileUploadException ex) {
          ex.printStackTrace();
        }
  
  // etc..
  </code></pre>