本文整理汇总了Java中org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload类的典型用法代码示例。如果您正苦于以下问题:Java ServletFileUpload类的具体用法?Java ServletFileUpload怎么用?Java ServletFileUpload使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServletFileUpload类属于org.apache.tomcat.util.http.fileupload.servlet包,在下文中一共展示了ServletFileUpload类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parsePhoto
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; //导入依赖的package包/类
protected String parsePhoto(HttpServletRequest request) {
String photo = null;
ServletFileUpload fileUpload = new ServletFileUpload();
try {
FileItemIterator items = fileUpload.getItemIterator(request);
while (items.hasNext()) {
FileItemStream item = items.next();
System.out.println("ITEM UPLOAD: " + item.getName());
System.out.println(item.openStream());
photo = item.getName();
InputStream is = item.openStream();
byte [] buffer = new byte [1024];
OutputStream os = new FileOutputStream(new File(pathToDownload + item.getName()));
int read = 0;
while ((read = is.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
os.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return photo;
}
示例2: WebappContext
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; //导入依赖的package包/类
public WebappContext(ServletContext servletContext, OpenOffice openOffice) {
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
fileUpload = new ServletFileUpload(fileItemFactory);
if (openOffice.getFileSizeMax() != null) {
fileUpload.setFileSizeMax(Integer.parseInt(openOffice.getFileSizeMax()));
logger.info("max file upload size set to " + openOffice.getFileSizeMax());
} else {
logger.warn("max file upload size not set");
}
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
if (openOffice.getPort() != null) {
String ports = openOffice.getPort();
String[] portArr = ports.split(",");
int[] portArrInt = new int[portArr.length];
int i = 0;
for (String port : portArr){
portArrInt[i++] = Integer.parseInt(port);
}
configuration.setPortNumbers(portArrInt);
}
if (openOffice.getHome() != null) {
configuration.setOfficeHome(new File(openOffice.getHome()));
}
if (StringUtils.isNotBlank(openOffice.getProfile())) {
configuration.setTemplateProfileDir(new File(openOffice.getProfile()));
}
officeManager = configuration.buildOfficeManager();
documentConverter = new OfficeDocumentConverter(officeManager);
}
示例3: FormUploadHelper
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; //导入依赖的package包/类
public FormUploadHelper(HttpServletRequest request) throws FileUploadException, IOException
{
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext())
{
FileItemStream item = iter.next();
if (!item.isFormField())
{
InputStream is = item.openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream(is.available());
int c;
while ((c = is.read()) != -1) {
bos.write(c);
}
files.put(item.getFieldName(), bos);
}
else
{
StringBuilder sb = TextUtils.toStringBuilder(item.openStream(), new StringBuilder(), true);
ArrayList<String> a = fields.get(item.getFieldName());
if (a == null) {
a = new ArrayList<>();
}
a.add(sb.toString().trim());
fields.put(item.getFieldName(), a);
}
}
}
示例4: init
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; //导入依赖的package包/类
@Override
public void init() throws ServletException {
DiskFileItemFactory fileFactory = new DiskFileItemFactory();
File filesDir = (File) getServletContext().getAttribute("FILE_DIR_FILE");
fileFactory.setRepository(filesDir);
this.uploader = new ServletFileUpload(fileFactory);
}
示例5: doPost
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; //导入依赖的package包/类
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
if(!ServletFileUpload.isMultipartContent(request)){
throw new ServletException("Content type is not multipart/form-data");
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("<html><head></head><body>");
try {
List<FileItem> fileItemsList = uploader.parseRequest(request);
Iterator<FileItem> fileItemsIterator = fileItemsList.iterator();
while(fileItemsIterator.hasNext()){
FileItem fileItem = fileItemsIterator.next();
System.out.println("FieldName = " + fileItem.getFieldName());
System.out.println("FileName = " + fileItem.getName());
System.out.println("ContentType = " + fileItem.getContentType());
System.out.println("Size(byte) = " + fileItem.getSize());
File file = new File(request.getServletContext().getAttribute("FILE_DIR") + File.separator + fileItem.getName());
System.out.println("Absolute Path at server = " + file.getAbsolutePath());
fileItem.write(file);
out.write("File " + fileItem.getName() + "uploaded successfully." + "<br/>");
out.write("<a href=\"UploadDownloadFileServlet?fileName=" + fileItem.getName() + "\"> Download" + fileItem.getName() + "</a>");
}
} catch (Exception e) {
// TODO: handle exception
out.write("Exception in uploading fiile");
}
out.write("</body></html>");
}
示例6: getFileUpload
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; //导入依赖的package包/类
public ServletFileUpload getFileUpload() {
return fileUpload;
}
示例7: isMultiPartContent
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; //导入依赖的package包/类
public static boolean isMultiPartContent(HttpServletRequest request)
{
return ServletFileUpload.isMultipartContent(request);
}