本文整理汇总了Java中org.apache.commons.fileupload.servlet.ServletFileUpload.setProgressListener方法的典型用法代码示例。如果您正苦于以下问题:Java ServletFileUpload.setProgressListener方法的具体用法?Java ServletFileUpload.setProgressListener怎么用?Java ServletFileUpload.setProgressListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.fileupload.servlet.ServletFileUpload
的用法示例。
在下文中一共展示了ServletFileUpload.setProgressListener方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MultipartUploadReader
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* Creates a new Reader for reading the given HTTP request. This must be a multipart request.
* @param pFoxRequest
*/
public MultipartUploadReader(FoxRequest pFoxRequest) {
try {
// New file upload handler
mServletFileUploadUpload = new ServletFileUpload();
// Create a progress listener for this upload
mFiletransferProgressListener = new FiletransferProgressListener();
// Attach the progress listener to this upload
mServletFileUploadUpload.setProgressListener(mFiletransferProgressListener);
//mUploadInfo.setProgressListener(mFiletransferProgressListener);
// Parse the upload request
mItemIterator = mServletFileUploadUpload.getItemIterator(pFoxRequest.getHttpRequest());
}
catch (Throwable ex) {
throw new ExInternal("Error encountered while trying to initialise a file upload work item.\nOriginal error: " + ex.getMessage());
}
}
示例2: newFileUpload
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
protected FileUpload newFileUpload(FileItemFactory fileItemFactory) {
ServletFileUpload upload = new ServletFileUpload(fileItemFactory);
upload.setSizeMax(-1);
if (request != null) {
// 注入监听
FileUploadProgressListener uploadProgressListener = new FileUploadProgressListener();
upload.setProgressListener(uploadProgressListener);
request.getSession().setAttribute(C.UPLOAD_PROGRESS_LISTENER_KEY, uploadProgressListener);
}
return upload;
}
示例3: getFileUploadComponent
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
private ServletFileUpload getFileUploadComponent()
{
DiskFileItemFactory dif=new DiskFileItemFactory();
if(factorySizeThreshold!=DEFAULT_SIZE_THRESHOLD)
{
dif.setSizeThreshold(factorySizeThreshold);
}
if(factoryRepository!=null)
{
dif.setRepository(new File(factoryRepository));
}
if(factoryCleaningTracker!=null)
{
dif.setFileCleaningTracker(factoryCleaningTracker);
}
ServletFileUpload sfu=new ServletFileUpload(dif);
if(sizeMax!=NO_LIMIT_SIZE_MAX)
{
sfu.setSizeMax(sizeMax);
}
if(fileSizeMax!=NO_LIMIT_FILE_SIZE_MAX)
{
sfu.setFileSizeMax(fileSizeMax);
}
if(servletHeaderencoding!=null)
{
sfu.setHeaderEncoding(servletHeaderencoding);
}
if(servletProgressListener!=null)
{
sfu.setProgressListener(servletProgressListener);
}
return sfu;
}
示例4: parse
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@SuppressWarnings({"unchecked", "PMD.CyclomaticComplexity" })
public void parse(HttpServletRequest servletRequest, String saveDir) throws IOException {
DiskFileItemFactory fac = new DiskFileItemFactory();
fac.setSizeThreshold(0);
if (saveDir != null) {
fac.setRepository(new File(saveDir));
}
ProgressMonitor monitor = null;
try {
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setSizeMax(maxSize);
monitor = new ProgressMonitor();
upload.setProgressListener(monitor);
String uploadKey = getUploadKey(servletRequest);
servletRequest.getSession().setAttribute(uploadKey, monitor);
List<FileItem> items = (List<FileItem>) upload.parseRequest(createRequestContext(servletRequest));
for (FileItem item : items) {
LOG.debug((new StringBuilder()).append("Found item ").append(item.getFieldName()).toString());
if (item.isFormField()) {
handleFormField(servletRequest, item);
} else {
handleFileUpload(item);
}
}
handleChunkedUploadHeaders(servletRequest);
} catch (FileUploadException e) {
if (monitor != null) {
monitor.abort();
}
LOG.warn("Error processing upload", e);
errors.add(e.getMessage());
}
}
示例5: doPost
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello<br/>");
boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
if (!isMultipartContent) {
out.println("You are not trying to upload<br/>");
return;
}
out.println("You are trying to upload<br/>");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// upload.setSizeMax(MAX_UPLOAD_IN_MEGS * 1024 * 1024);
ProgressListener testProgressListener = new ProgressListener();
upload.setProgressListener(testProgressListener);
HttpSession session = request.getSession();
session.setAttribute("testProgressListener", testProgressListener);
try {
List<FileItem> fields = upload.parseRequest(request);
out.println("Number of fields: " + fields.size() + "<br/><br/>");
Iterator<FileItem> it = fields.iterator();
if (!it.hasNext()) {
out.println("No fields found");
return;
}
out.println("<table border=\"1\">");
while (it.hasNext()) {
out.println("<tr>");
FileItem fileItem = it.next();
boolean isFormField = fileItem.isFormField();
if (isFormField) {
out.println("<td>regular form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
"<br/>STRING: " + fileItem.getString()
);
out.println("</td>");
} else {
out.println("<td>file form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
// "<br/>STRING: " + fileItem.getString() +
"<br/>NAME: " + fileItem.getName() +
"<br/>CONTENT TYPE: " + fileItem.getContentType() +
"<br/>SIZE (BYTES): " + fileItem.getSize() +
"<br/>TO STRING: " + fileItem.toString()
);
out.println("</td>");
}
out.println("</tr>");
}
out.println("</table>");
} catch (FileUploadException e) {
out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}