//DiskFileItemFactory:创建FileItem对象的工厂
//创建DiskFileItemFactory对象
DiskFileItemFactory factory = new DiskFileItemFactory();
//ServletFileUpload:负责处理上传的文件数据,并将表单中每个输入项封装成一个FileItem对象
//使用DiskFileItemFactory对象创建ServletFileUpload对象
ServletFileUpload upload = new ServletFileUpload(factory);
//调用ServletFileUpload.parseRequest方法解析request对象,得到一个保存了所有上传内容的List
List<FileItem> items = upload.parseRequest(request);
for (FileItem fileItem : items) {
if(!fileItem.isFormField()){//判断某项是否为普通的表单类型
String fileName = fileItem.getName();
String basePath = AppPathUtil.getEnterpriseAttachmentPath("100000");
String newfilename = String.valueOf(new Date().getTime());
String suffix = fileName.substring(fileName.lastIndexOf(".")+1).toLowerCase();
String newname = newfilename+"."+suffix;
StringBuffer sbRealPath = new StringBuffer();
sbRealPath.append(basePath).append("\\").append(newname);
File file = new File(sbRealPath.toString());
fileItem.write(file);
}else {
if("commonhiddentrouble".equals(fileItem.getFieldName())){
commonhiddentrouble = fileItem.getString("UTF-8");
}
if("commonhiddentroublezg".equals(fileItem.getFieldName())){
commonhiddentroublezg = fileItem.getString("UTF-8");
}
}
}
Java接收http请求
Posted tianxinrj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java接收http请求相关的知识,希望对你有一定的参考价值。
以上是关于Java接收http请求的主要内容,如果未能解决你的问题,请参考以下文章