commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From εδΈ‰ιƒŽ <>
Subject [fileupload]how to get progress stats from diffrent request.
Date Mon, 12 Aug 2013 06:12:21 GMT
   if i upload only one file,i save the percent stats to session,i can get the currect stats
from ProgressListener.

  if i upload two file f1,f2 in same session,but diffrent request.i cant distinguish the two
  to solve this problem,
    1.i add a text field named "key" to distinguish two form action.
    2.pass value of "key" to ProgressListener.

  for example:
  i will post in diffrent request:
    <form method=post enctype=multipart/form-data>
      <input type=text name=key value=f1 >
      <input type=file name=file1 >
    <form method=post enctype=multipart/form-data>
      <input type=text name=key value=f2 >
      <input type=file name=file2 >

  i define my ProgressListener:
   public class UploadPro implements ProgressListener {
    private HttpServletRequest request;
    private String keyi;
    private DecimalFormat df = new DecimalFormat("#00.0");    //"#00.0"
    public UploadPro(HttpServletRequest request,String key){  
        this.request = request;
    public void update(long bytesRead, long bytesTotal, int items) {  
        double percent= (double)bytesRead*100/(double)bytesTotal;
        System.out.println("percent :"+df.format(percent));
        request.getSession().setAttribute("UPLOAD_PERCENTAGE_"+key, df.format(percent)); 

  thus,the diffrent progress stats saved in diffrent session  variable("UPLOAD_PERCENTAGE_"+key).

  to pass key value to ProgressListener,i must get value of parameter "key" before setProgressListener.
  my code write like this:
  List<FileItem> fileItems = upload.parseRequest(request);
  FileItem key=fileItems.get(0);            
  upload.setProgressListener(new UploadPro(request,key.getString));
  i run the project,i find ProgressListener do not work.and no exception message printed.
  so,i find ProgressListener not work if method setProgressListener called after method parseRequest.
  if setProgressListener before parseRequest,the code run correct,but i cant get parameter

  so, how to get progress stats from diffrent request(same session)????
  thanks very much!!!

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message