本文整理汇总了Java中org.apache.struts.upload.FormFile.getFileSize方法的典型用法代码示例。如果您正苦于以下问题:Java FormFile.getFileSize方法的具体用法?Java FormFile.getFileSize怎么用?Java FormFile.getFileSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.struts.upload.FormFile
的用法示例。
在下文中一共展示了FormFile.getFileSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.struts.upload.FormFile; //导入方法依赖的package包/类
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (isCancelled(request)) {
return mapping.findForward("sysadmin");
}
IImportService importService = AdminServiceProxy.getImportService(getServlet().getServletContext());
ImportExcelForm importForm = (ImportExcelForm) form;
importForm.setOrgId(0);
FormFile file = importForm.getFile();
// validation
if (file == null || file.getFileSize() <= 0) {
return mapping.findForward("importGroups");
}
List results = importService.parseGroupSpreadsheet(file);
request.setAttribute("results", results);
return mapping.findForward("importGroups");
}
示例2: setFile
import org.apache.struts.upload.FormFile; //导入方法依赖的package包/类
public void setFile(int number, FormFile file) {
if (file.getFileSize() > 0) {
if (this.file == null) {
this.file = new ArrayList<FormFile>();
}
while (number >= this.file.size()) {
this.file.add(null);
}
this.file.set(number, file);
}
}
示例3: execute
import org.apache.struts.upload.FormFile; //导入方法依赖的package包/类
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (isCancelled(request)) {
return mapping.findForward("sysadmin");
}
IImportService importService = AdminServiceProxy.getImportService(getServlet().getServletContext());
ImportExcelForm importExcelForm = (ImportExcelForm) form;
FormFile file = importExcelForm.getFile();
// validation
if (file == null || file.getFileSize() <= 0) {
return mapping.findForward("import");
}
String sessionId = SessionManager.getSession().getId();
SessionManager.getSession().setAttribute(IImportService.IMPORT_FILE, file);
// use a new thread only if number of users is > threshold
if (importService.getNumRows(file) < IImportService.THRESHOLD) {
List results = importService.parseSpreadsheet(file, sessionId);
SessionManager.getSession(sessionId).setAttribute(IImportService.IMPORT_RESULTS, results);
return mapping.findForward("results");
} else {
Thread t = new Thread(new ImportExcelThread(sessionId));
t.start();
return mapping.findForward("status");
}
}
示例4: validateFileSize
import org.apache.struts.upload.FormFile; //导入方法依赖的package包/类
/**
*
* @param file
* @param largeFile
* @param errorKey
* the key in ActionMessages(errorKey,ActionMessage());
* @param errors
* @return Be careful, if the file size is under maximum size, return TRUE. Otherwise, return false.
*/
public static boolean validateFileSize(FormFile file, boolean largeFile, String errorKey, ActionMessages errors) {
int fileSize = 0;
try {
fileSize = file.getFileSize();
} catch (Exception e) {
//skip, do nothing
return true;
}
return FileValidatorUtil.validateFileSize(fileSize, largeFile, errorKey, errors);
}
示例5: doUpload
import org.apache.struts.upload.FormFile; //导入方法依赖的package包/类
/**
* Uploads file from request and
*
* @param mapping the ActionMapping
* @param form the ActionForm
* @param request the Request
* @param response the Response
* @return NOT YET DOCUMENTED
* @exception Exception NOT YET DOCUMENTED
*/
ActionForward doUpload(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
prtln("doUpload");
ActionErrors errors = new ActionErrors();
FileUploadForm uploadForm = (FileUploadForm) form;
// clear values to be calculated ...
// uploadForm.setUploadedResourceHandle(null);
uploadForm.setContentURL(null);
// Process the FormFile
FormFile myFile = uploadForm.getMyFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
prtln("contentType: " + contentType);
prtln("fileName: " + fileName);
prtln("fileSize: " + fileSize);
try {
NDRToolkit tk = new NDRToolkit();
// hack to use same resource over and over
/* String tmpResourceHandle = "2200/test.20090410170951993T"; // TEMPORARY
Resource cannedResource = tk.getResource(tmpResourceHandle); */
// production:
Resource resource = tk.newResource();
String uploadedResourceHandle = tk.setResourceContent(resource, fileData, fileName);
// must UPDATE to get the contentURL property!
Resource updatedResource = tk.getResource(uploadedResourceHandle);
uploadForm.setContentURL(updatedResource.getContentURL().toString());
} catch (Throwable t) {
t.printStackTrace();
errors.add("error", new ActionError("generic.error", t.getMessage()));
saveErrors(request, errors);
return mapping.findForward("ndr.upload.form");
}
String forwardPath = request.getParameter("forwardPath");
if (forwardPath != null && forwardPath.trim().length() > 0)
return new ActionForward(forwardPath);
else
return mapping.findForward("ndr.upload.confirm");
}