java - Make servlet work in background -
I have a file uploading software and UI on my JSP.
& lt; Form method = "post" action = "mygeco" enctype = "multipart / form-data" style = "position: full; left: 30%; bottom: 2%;" & Gt; & Lt; Input type = "file" name = "datafile" id = "choose file" / gt; & Amp; Nbsp; & Lt; Input type = "submit" value = "upload" multiple = "multiple" /> & Lt; / Form & gt; File uploading is done on my Dopost method, and I have other code for my doget () method, so when I press the Upload button on my JSP page I want to upload. I am going to be in the background when the user lives on the jsp page and returns a warning after upload, how can I do this? Protects zero doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto generated method is Stub Boolean Multipart = ServletFileUpload.isMultipartContent (request); Response.setContentType ("text / html"); If (IsMultipart) {// Create a factory for disk-based file items FileItemFactory factory = new diskfile itemfactor (); // Create a new file upload handler: ServletFile Upload Upload = New ServletFileUpload (Factory); Try {// Pars request list item = upload.parseRequest (request); Iterator iterator = item Knitter (); System.out.println ("Start Saver"); While (iterator.hasNext ()) {file item item = (file system) iterator.next (); If (! Item.isFormField ()) {string filename = item.getName (); String root = getServletContext (). GetRealPath ("/"); File path = new file ("/ u / poolla / workspace / firstserve /"); If (! Path.exists ()) {Boolean status = path.mkdirs (); } File uploaded file = new file (path + "/" + filename); Println (uploadedFile.getAbsolutePath ()); If (fileName! = "") Item.write (uploaded file); Else System.out.println ("File not found"); System.out.println ("& lt; h1> Uploaded file successfully ....: -) ";); } Else {String abc = item.getString (); Println ("<
" + ABC + "
; "); }}} Hold (FileUploadException e) {System.out.println (e); } Hold (exception e) {System.out.println (e); }} Else {System.out.println ("not multiparty"); }}}
You can use Ajax for that,
Upload the file via Ajax call,
Comments
Post a Comment