如何使用公共进度更新到多用户环境?
现在我正在使用 servlet 上传文件并通过实现 ProgressListener 类更新进度。实现 ProgressListener 静态变量的类。我该如何将变量移动到一个对象并使其对于每个用户都是唯一的。
实现 ProgressListener 的类:
package com.pricar.uploadlistener.pack;
import java.text.NumberFormat;
import org.apache.commons.fileupload.ProgressListener;
public class FileUploadProgressListener implements ProgressListener {
public FileUploadProgressListener() {
}
private static long bytesRead;
private static long totalBytes;
public void getFileUploadStatus() {
String per = NumberFormat.getPercentInstance().format( (double) bytesRead / (double) totalBytes );
String statusStr = (per.substring(0, per.length() - 1));
int status = Integer.parseInt(statusStr);
}
/* (non-Javadoc)
* @see org.apache.commons.fileupload.ProgressListener#update(long, long, int)
*/
public void update(long pBytesRead, long pContentLength, int pItems) {
bytesRead = pBytesRead;
totalBytes = pContentLength;
}
}
任何建议或链接将更加感激!
谢谢!!
Now i am uploading files with servlet and update progress with implementing ProgressListener class. The class that implements ProgressListener Static Variables. How shall i move the variables to an object and make it unique for each user.
The Class Implementing ProgressListener:
package com.pricar.uploadlistener.pack;
import java.text.NumberFormat;
import org.apache.commons.fileupload.ProgressListener;
public class FileUploadProgressListener implements ProgressListener {
public FileUploadProgressListener() {
}
private static long bytesRead;
private static long totalBytes;
public void getFileUploadStatus() {
String per = NumberFormat.getPercentInstance().format( (double) bytesRead / (double) totalBytes );
String statusStr = (per.substring(0, per.length() - 1));
int status = Integer.parseInt(statusStr);
}
/* (non-Javadoc)
* @see org.apache.commons.fileupload.ProgressListener#update(long, long, int)
*/
public void update(long pBytesRead, long pContentLength, int pItems) {
bytesRead = pBytesRead;
totalBytes = pContentLength;
}
}
Any Suggestions or Link would be more appreciative!!
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将创建 bytesRead 和totalBytes 本地属性,因此 FileUploadProgressListener 的每个实例都有自己的数据。然后将该实例存储在会话变量中,以便每个用户都有自己的实例。
I would make bytesRead and totalBytes local attributes, so each instance of FileUploadProgressListener has its own data. Then store that instance in a session variable so every user gets their own.