当前位置 : 主页 > 编程语言 > c++ >

servlet 3.1 上传多张图片.java

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt package com.fz.servlet;import java.io.File;import java.io.IOException;import java.util.Collection;import java.util.UUID;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResp
gistfile1.txt
package com.fz.servlet;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;

@WebServlet("/ups.do") @MultipartConfig
public class Ups extends HttpServlet{

	@Override
	public void service(ServletRequest req, ServletResponse res)
			throws ServletException, IOException {
		HttpServletRequest request = (HttpServletRequest)req;
		String name = request.getParameter("name");
	//	Part part = request.getPart("ifile");
		//文件路径
		String path = this.getServletContext().getRealPath("upload/");
		File file = new File(path);
		if (!file.exists()) {
			file.mkdirs();
		}
		//获取文件集合
		Collection
 
   list = request.getParts();
		for (Part p : list) {
			if(p.getContentType()==null) continue;
			//设置文件大小
			int size = 1024*50;
			if (p.getSize()
 
网友评论