本文整理汇总了Java中org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest方法的典型用法代码示例。如果您正苦于以下问题:Java ServletFileUpload.parseRequest方法的具体用法?Java ServletFileUpload.parseRequest怎么用?Java ServletFileUpload.parseRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.fileupload.servlet.ServletFileUpload
的用法示例。
在下文中一共展示了ServletFileUpload.parseRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileItemList
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/** 获取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
if (!saveDir.isDirectory()) {
saveDir.mkdir();
}
List<?> fileItems = null;
RequestContext requestContext = new ServletRequestContext(request);
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(saveDir);
factory.setSizeThreshold(fileSizeThreshold);
ServletFileUpload upload = new ServletFileUpload(factory);
fileItems = upload.parseRequest(request);
}
return fileItems;
}
示例2: getFileItemList
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/** 获取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
if (!saveDir.isDirectory()) {
saveDir.mkdir();
}
List<?> fileItems = null;
RequestContext requestContext = new ServletRequestContext(request);
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(saveDir);
factory.setSizeThreshold(fileSizeThreshold);
ServletFileUpload upload = new ServletFileUpload(factory);
fileItems = upload.parseRequest(request);
}
return fileItems;
}
示例3: getFileItemList
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/** 获取所有文本域 */
public static List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
if (!saveDir.isDirectory()) {
saveDir.mkdir();
}
List<?> fileItems = null;
RequestContext requestContext = new ServletRequestContext(request);
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(saveDir);
factory.setSizeThreshold(fileSizeThreshold);
ServletFileUpload upload = new ServletFileUpload(factory);
fileItems = upload.parseRequest(request);
}
return fileItems;
}
示例4: importProject
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public void importProject(HttpServletRequest req, HttpServletResponse resp) throws Exception {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletContext servletContext = req.getSession().getServletContext();
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
factory.setRepository(repository);
ServletFileUpload upload = new ServletFileUpload(factory);
InputStream inputStream=null;
boolean overwriteProject=true;
List<FileItem> items = upload.parseRequest(req);
if(items.size()==0){
throw new ServletException("Upload file is invalid.");
}
for(FileItem item:items){
String name=item.getFieldName();
if(name.equals("overwriteProject")){
String overwriteProjectStr=new String(item.get());
overwriteProject=Boolean.valueOf(overwriteProjectStr);
}else if(name.equals("file")){
inputStream=item.getInputStream();
}
}
repositoryService.importXml(inputStream,overwriteProject);
IOUtils.closeQuietly(inputStream);
resp.sendRedirect(req.getContextPath()+"/urule/frame");
}
示例5: importExcelTemplate
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public void importExcelTemplate(HttpServletRequest req, HttpServletResponse resp) throws Exception {
DiskFileItemFactory factory=new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(req);
Iterator<FileItem> itr = items.iterator();
List<Map<String,Object>> mapData=null;
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
String name=item.getFieldName();
if(!name.equals("file")){
continue;
}
InputStream stream=item.getInputStream();
mapData=parseExcel(stream);
httpSessionKnowledgeCache.put(req, IMPORT_EXCEL_DATA, mapData);
stream.close();
break;
}
httpSessionKnowledgeCache.put(req, IMPORT_EXCEL_DATA, mapData);
writeObjectToJson(resp, mapData);
}
示例6: map
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public Map<String, Object> map(HttpServletRequest request) {
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
upload.setSizeMax(20 * 1024);
upload.setFileSizeMax(10 * 1024);
List<FileItem> items;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
throw new RequestMappingException("", e);
}
return items.stream().map(item -> {
String key = item.getFieldName();
if (item.isFormField()) {
String value = item.getString();
return new SimpleKeyValue<String, Object>(key, value);
} else {
return new SimpleKeyValue<String, Object>(key, item);
}
}).collect(Collectors.toMap(
SimpleKeyValue::getKey,
SimpleKeyValue::getValue
));
}
示例7: VariablesBase
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* Basic constructor that takes the request object and saves it to be used by the subsequent
* methods
*
* @param request
* HttpServletRequest object originating from the user request.
*/
@SuppressWarnings("unchecked")
public VariablesBase(HttpServletRequest request) {
if (request == null) {
// logging exception to obtain stack trace to pinpoint the cause
log4j.warn("Creating a VariablesBase with a null request", new Exception());
this.session = new HttpSessionWrapper();
this.isMultipart = false;
} else {
this.session = request.getSession(true);
this.httpRequest = request;
this.isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request));
if (isMultipart) {
DiskFileItemFactory factory = new DiskFileItemFactory();
// factory.setSizeThreshold(yourMaxMemorySize);
// factory.setRepositoryPath(yourTempDirectory);
ServletFileUpload upload = new ServletFileUpload(factory);
// upload.setSizeMax(yourMaxRequestSize);
try {
items = upload.parseRequest(request);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
示例8: parseMultipart
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Map<String, Object> parseMultipart(HttpServletRequest request)
throws IOException, ServletException {
ServletFileUpload upload = new ServletFileUpload(_uploadItemFactory);
List<FileItem> items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
throw new ServletException(e);
}
Map<String, Object> params = new HashMap<String, Object>();
for (FileItem item : items) {
if (item.isFormField())
params.put(item.getFieldName(), item.getString());
else
params.put(item.getFieldName(), item);
}
return params;
}
示例9: getMultipartContent
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public Map<String, FileItem> getMultipartContent() throws FileUploadException, IllegalAccessException {
if (!ServletFileUpload.isMultipartContent(request))
throw new IllegalAccessException();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
Map<String, FileItem> result = new HashMap<String, FileItem>();
@SuppressWarnings("unchecked")
List<FileItem> items = upload.parseRequest(request);
for (FileItem fi : items) {
result.put(fi.getFieldName(), fi);
}
return result;
}
示例10: getStringParametersMap
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public static ParsedRequest getStringParametersMap(HttpServletRequest request) throws FileUploadException {
HashMap<String, String> textMap = new HashMap<>();
ParsedRequest parsedRequest = new ParsedRequest(textMap, null);
try {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> uploadItems = upload.parseRequest(request);
for (FileItem item : uploadItems) {
String fieldName = item.getFieldName();
String value = item.getString();
textMap.put(fieldName, value);
}
} catch (Exception e) {
loggerFactory.error(e);
}
return parsedRequest;
}
示例11: 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 {
try {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
factory.setRepository(tempPathFile);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
List<FileItem> items = upload.parseRequest(request);// 得到所有的文件
Iterator<FileItem> i = items.iterator();
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();
if (fileName != null) {
File fullFile = new File(fi.getName());
File savedFile = new File(uploadPath, fullFile.getName());
fi.write(savedFile);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: getItems
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public HashMap getItems(HttpServletRequest request) throws ServiceException{
HashMap itemMap=null;
try {
String tempPath = System.getProperty("java.io.tmpdir");
FileItemFactory factory = new DiskFileItemFactory(4096,new File(tempPath));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1000000);
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
itemMap=new HashMap();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
itemMap.put(item.getFieldName(), item.getString());
} else {
itemMap.put(item.getFieldName(), item);
}
}
} catch (Exception e) {
e.printStackTrace();
throw ServiceException.FAILURE("FileUploadHandler.getItems", e);
}
return itemMap;
}
示例13: getValueFromUploadForm
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* 功能: 从上传的request中得到普通字符值,一定要注意只能调用一次
* @param request
* @param fieldName
* @return
*/
public static String getValueFromUploadForm(HttpServletRequest request, String fieldName) {
String returnValue = null;
try {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
List lItems = sfu.parseRequest(request);
java.util.Iterator iter = lItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (fieldName.equals(item.getFieldName())) {
returnValue = item.getString();
break;
}
}
} catch (FileUploadException e) {
e.printStackTrace();
}
return returnValue;
}
示例14: uploadExcel
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public HSSFSheet uploadExcel(HttpServletRequest request)
throws IOException, FileUploadException {
ServletFileUpload fileupload = new ServletFileUpload(
new DiskFileItemFactory());
fileupload.setSizeMax(1024 * 1024 * 10);
@SuppressWarnings("unchecked")
List<FileItem> fileitems = fileupload.parseRequest(request);
InputStream inputStream = null;
for (FileItem fileitem : fileitems) {
if (!fileitem.isFormField()) {
inputStream = fileitem.getInputStream();
break;
}
}
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
return workbook.getSheetAt(0);
}
示例15: getParametersMap
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public static ParsedRequest getParametersMap(HttpServletRequest request) throws FileUploadException {
HashMap<String, String> textMap = new HashMap<>();
HashMap<String, File> fileMap = new HashMap<>();
ParsedRequest parsedRequest = new ParsedRequest(textMap, fileMap);
try {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> uploadItems = upload.parseRequest(request);
for (FileItem item : uploadItems) {
String fieldName = item.getFieldName();
if (item.isFormField()) {
String value = item.getString();
textMap.put(fieldName, value);
} else {
String filename = FilenameUtils.getName(item.getName());
InputStream fileContent = item.getInputStream();
File file = new File(ServerConsts.tempFileStore + "/" + filename);
FileHelper.saveToFile(fileContent, file);
fileMap.put(fieldName, file);
}
}
} catch (Exception e) {
loggerFactory.error(e);
}
return parsedRequest;
}