title: Bootstrap File Input JQuery Plugin designed by Krajee (SyntaxError: Unexpected end of input)
body: <p>I have a problem. I used this  <a href="http://plugins.krajee.com/file-input/demo" rel="nofollow noreferrer">http://plugins.krajee.com/file-input/demo</a> for file uploading, all right, file successfully uploading on server, but on jsp page show message "SyntaxError: Unexpected end of input.", although file has been successfully uploaded on server. <img src="https://i.stack.imgur.com/NrZRK.png" alt="File uploaded">
  <img src="https://i.stack.imgur.com/WvHtW.png" alt="But on jsp page error mes"></p>
  
  <p>My servlet, i think problem here (maybe with JSON).</p>
  
  <pre><code>public class UploadImageCommand implements ActionCommand {
  
  enum Type {
  
      IMAGES("/upload/images", ".jpg", ".bmp", ".gif", ".png", ".jpeg"),
      VIDEOS("/upload/videos", ".avi", ".mpeg", ".mpg", ".mp4", ".mov", ".mkv", ".flv"),
      MUSICS("/upload/musics", ".mp3", ".wav");
  
      private String path;
      private String[] formats;
  
      Type(String path, String... format) {
          this.path = path;
          this.formats = format;
      }
  
      public String[] getFormats() {
          return formats;
      }
  
      public String getPath() {
          return path;
      }
  }
  
  private static String parseFileFormat(String fileName) {
      fileName = fileName.toLowerCase();
      int dotPosition = fileName.lastIndexOf(".");
      String format = fileName.substring(dotPosition, fileName.length());
      return format;
  }
  
  private Type getType(String fileName) {
      String format = parseFileFormat(fileName);
      Type[] values = Type.values();
      for (int i = 0; i &lt; values.length; i++) {
          for (int j = 0; j &lt; values[i].getFormats().length; j++) {
              if (values[i] == Type.IMAGES &amp;&amp; values[i].getFormats()[j].equals(format)) {
                  return Type.IMAGES;
              } else if (values[i] == Type.VIDEOS &amp;&amp; values[i].getFormats()[j].equals(format)) {
                  return Type.VIDEOS;
              } else if (values[i] == Type.MUSICS &amp;&amp; values[i].getFormats()[j].equals(format)) {
                  return Type.MUSICS;
              }
          }
      }
      return null;
  }
  
  @Override
  public void execute(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
  
      ServletContext context = request.getSession().getServletContext();
      if (ServletFileUpload.isMultipartContent(request)) {
          try {
              String fileName = null;
              String filePath;
              Type type = null;
              List&lt;FileItem&gt; multiparts = new ServletFileUpload(
                      new DiskFileItemFactory()).parseRequest(request);
              System.out.println("Multipart size: " + multiparts.size());
              for (FileItem item : multiparts) {
                  if (item.getName() == null || item.getName() == "") {
                      continue;
                  }
                  System.out.println("Part : " + item.getName());
                  if (!item.isFormField()) {
                      fileName = new File(item.getName()).getName();
                      type = getType(fileName);
                      filePath = context.getRealPath(type.path);
                      if (type != null) {
                          SecureRandom random = new SecureRandom();
                          fileName = new BigInteger(130, random).toString(32) +
                                  parseFileFormat(fileName);
                          item.write(new File(filePath + File.separator + fileName));
                          System.out.println("File uploaded successfully");
                          // System.out.println("File path: " + context.getRealPath(type.path));
                      } else {
                          throw new IllegalStateException("Wrong file format!");
                      }
                  }
              }
              // response.getWriter().print(json.toString());
          } catch (Exception e) {
              e.printStackTrace();
          }
      } else {
          System.out.println("Sorry this Servlet only handles file upload request");
      }
      response.setContentType("application/json");
  } 
  </code></pre>
  
  <p>}</p>