java - Bootstrap File Input JQuery Plugin designed by Krajee (SyntaxError: Unexpected end of input) -


i have problem. used http://plugins.krajee.com/file-input/demo file uploading, right, file uploading on server, on jsp page show message "syntaxerror: unexpected end of input.", although file has been uploaded on server. file uploaded but on jsp page error mes

my servlet, think problem here (maybe json).

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();     (int = 0; < values.length; i++) {         (int j = 0; j < values[i].getformats().length; j++) {             if (values[i] == type.images && values[i].getformats()[j].equals(format)) {                 return type.images;             } else if (values[i] == type.videos && values[i].getformats()[j].equals(format)) {                 return type.videos;             } else if (values[i] == type.musics && 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<fileitem> multiparts = new servletfileupload(                     new diskfileitemfactory()).parserequest(request);             system.out.println("multipart size: " + multiparts.size());             (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 servlet handles file upload request");     }     response.setcontenttype("application/json"); }  

}

as noticed in http://plugins.krajee.com/file-input#async-send:

you must send valid json response server, else upload process fail. if not encounter error, must @ least send empty json object {} server.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -