首页>代码>Java Web之文件上传项目实例>/upload/src/service3/upload3.java
package service3;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;

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

import org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement;

/**
 * Servlet3.0文件上传下载
 */
@WebServlet("/upload3")
@MultipartConfig
public class upload3 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取普通上传组件
		String username = request.getParameter("username");
		System.out.println(username);
		
		//获取文件上传组件
		//获取文件对象
		Collection<Part> parts = request.getParts();
		for (Part part : parts) {
			//获取表单提交页面name的属性值
			String name = part.getName();
			
			//获取文件的大小
			long size = part.getSize();
			
			//获取文件真实文件名
			String header = part.getHeader("content-disposition");
			String realName=header.substring(header.indexOf("filename=")+10,header.length()-1);
			
			
			System.out.println("文件名:"+realName+"表单文件name名:"+name+"文件大小:"+size+"文件对象:"+part);
			
		}
		
		
		
		
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
最近下载更多
hongdongdong  LV12 2023年11月18日
Mayoubin2001  LV21 2022年3月26日
森屿海巷@  LV1 2021年11月24日
liu222  LV7 2021年5月6日
jokonem  LV5 2021年2月19日
2977376  LV1 2020年7月9日
lyd19931203  LV21 2020年6月16日
wxd1997  LV13 2020年1月10日
36-----  LV2 2019年12月26日
admin0019  LV2 2019年11月3日
最近浏览更多
uni-code_0123  LV1 2023年11月29日
hongdongdong  LV12 2023年11月18日
19050126312  LV1 2023年10月19日
asadda  LV2 2023年6月27日
xiaoxiexie  LV13 2022年11月13日
softandroad 2022年11月8日
暂无贡献等级
是你爸爸啊100  LV5 2022年8月5日
不花钱 2022年4月2日
暂无贡献等级
Mayoubin2001  LV21 2022年3月26日
dongzhan  LV12 2021年12月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友