java - how to monitor progress of uploading file in servlet 3.1 -
i want monitor progress of file getting uploaded m using servlet 3.1
i know specs of servlet 3.1 , don't need apache common fileupload can part class
i did this
inputstream inputstream = null; double s; string size=null; string contenttype=null; string submittedname=null; string tim=null; string actuallocation=null; system.out.println("getting here"); part filepart = request.getpart("file"); system.out.println("getting here"); if(description.equals("")) { system.out.println("please provide description file"); } else{ if (filepart != null ) { s=(double)filepart.getsize(); double mb=(s/1048576); if(mb != 0) { size=string.valueof((float)mb); contenttype=filepart.getcontenttype(); submittedname=getformatted(filepart.getsubmittedfilename()); tim=string.valueof(system.currenttimemillis()); actuallocation=name+"-"+commun+"-"+tim+"-"+submittedname; system.out.println("getting there"); inputstream = filepart.getinputstream(); system.out.println("getting here & there"); try { file file=new file(x,actuallocation); files.copy(inputstream, file.topath()); }
i know can use listener monitor progress , but main question should set progress listener thought should set part filepart.before system.out.println("getting here")
u can see chrome displaying progress of uploading (in bottom)(but want more impressive progress bar)
when ran project thought in console i'll see "getting here " while uploading found control not coming part unless uploading completed.
i'm bit confuse @ segment uploading happening , should set progress listener
you don't need in server side upload progress bar. can using javascript
, html
, css
.
if using jquery
take @ pugin http://malsup.com/jquery/form/. here file upload progress bar demo link http://malsup.com/jquery/form/progress.html. there 2 more demos , plenty more examples in website.
and can take @ tutorial http://codular.com/javascript-ajax-file-upload-with-progress doing html5
, javascript
. ignore php
part.
you should not have change in java
code, cause servlet
method hit after file upload has been completed.
Comments
Post a Comment