news 2026/4/18 9:39:07

Tomcat 9 多个文件上传

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Tomcat 9 多个文件上传

MulUp.jsp jsp文件

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Tomcat 9 多个文件上传</title> </head> <body> <b>多个文件上传至服务器:</b> <form action="<%=request.getContextPath()%>/smallRianMulFileup" method="post" enctype="multipart/form-data"> 请选择文件:<input type="file" name="smallRianFile" width="120" height="120"><br> 请选择文件:<input type="file" name="smallRianFileOne" width="120" height="120"><br> <input type="submit" value="提交" width="120" height="120"> </form> </body>

java 文件

package org.rain.servlet; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.List; 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; @WebServlet("/smallRianMulFileup") @MultipartConfig public class SmallRainMulFileUp extends HttpServlet { final static String SMALL_RAIN_PATH = "C:/SmallRianUp"; @Override public void init() throws ServletException { File smallRainFileSaveDir = new File(SMALL_RAIN_PATH); if (!smallRainFileSaveDir.exists()) { smallRainFileSaveDir.mkdir(); } } @Override public void doGet(HttpServletRequest smallRainREQ, HttpServletResponse smallRainRe) throws ServletException, IOException { smallRainRe.setCharacterEncoding("UTF-8"); smallRainRe.setContentType("text/html;charset=UTF-8"); smallRainRe.getWriter().println("<b>非法访问!</b>"); } @Override protected void doPost(HttpServletRequest smallRainRequest, HttpServletResponse smallRainResponse) throws ServletException, IOException { File smallRainFileSaveDir = new File(SMALL_RAIN_PATH); if (!smallRainFileSaveDir.exists()) { smallRainFileSaveDir.mkdir(); } smallRainRequest.setCharacterEncoding("UTF-8"); Collection<Part> smallRainFilesPart = smallRainRequest.getParts(); String smallRainLocalFile = null; List<String> smallRainFiles = new ArrayList<String>(); for (Part smallRainPart : smallRainFilesPart) { String smallRainFileName = smallRainPart.getSubmittedFileName(); smallRainLocalFile = SMALL_RAIN_PATH + File.separator + smallRainFileName; boolean smallRainHasFile = false; if (null != smallRainLocalFile && smallRainLocalFile.length() > 0 && smallRainPart.getSize() > 0) { smallRainPart.write(smallRainLocalFile); smallRainFiles.add(smallRainFileName); } } smallRainResponse.setCharacterEncoding("UTF-8"); PrintWriter smallRainOut = smallRainResponse.getWriter(); String smallRainHead = new String( "<head> <meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\"> </head>"); smallRainOut.println("<html>"); smallRainOut.println(smallRainHead); smallRainOut.println("<title>文件上传成功列表:</title>"); smallRainOut.println("<body>"); for (String smallRainUpFile : smallRainFiles) { smallRainOut.println("<h3>" + smallRainUpFile + " 上传成功" + "</h3>"); } smallRainOut.println("</body>"); smallRainOut.println("</html>"); } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/18 8:53:16

VASPsol隐式溶剂模型:3步掌握DFT计算的溶剂效应模拟

VASPsol隐式溶剂模型&#xff1a;3步掌握DFT计算的溶剂效应模拟 【免费下载链接】VASPsol Solvation model for the plane wave DFT code VASP. 项目地址: https://gitcode.com/gh_mirrors/va/VASPsol 在密度泛函理论(DFT)计算中&#xff0c;准确模拟溶剂环境对于研究化…

作者头像 李华
网站建设 2026/4/17 6:12:57

Honey Select 2增强补丁完整指南:5步解决游戏显示与功能问题

Honey Select 2增强补丁完整指南&#xff1a;5步解决游戏显示与功能问题 【免费下载链接】HS2-HF_Patch Automatically translate, uncensor and update HoneySelect2! 项目地址: https://gitcode.com/gh_mirrors/hs/HS2-HF_Patch 还在为Honey Select 2游戏中的角色显示…

作者头像 李华
网站建设 2026/4/11 19:35:55

从零到上线:周末搞定你的第一个万物识别应用

从零到上线&#xff1a;周末搞定你的第一个万物识别应用 作为一名业余编程爱好者&#xff0c;你是否曾想开发一个能识别日常物品的趣味应用&#xff0c;却被深度学习框架复杂的依赖关系搞得焦头烂额&#xff1f;本文将带你使用预置镜像快速搭建一个万物识别应用&#xff0c;无需…

作者头像 李华
网站建设 2026/4/18 8:40:28

百度网盘秒传技术深度解析与实战应用

百度网盘秒传技术深度解析与实战应用 【免费下载链接】rapid-upload-userscript-doc 秒传链接提取脚本 - 文档&教程 项目地址: https://gitcode.com/gh_mirrors/ra/rapid-upload-userscript-doc 还在为百度网盘文件转存效率低下而烦恼吗&#xff1f;面对频繁失效的分…

作者头像 李华
网站建设 2026/4/15 21:14:48

边缘计算方案:将万物识别模型轻量化部署的捷径

边缘计算方案&#xff1a;将万物识别模型轻量化部署的捷径 在物联网和边缘计算场景中&#xff0c;将AI模型部署到树莓派等资源受限设备一直是个技术难点。尤其是万物识别这类需要实时处理图像的任务&#xff0c;传统方案往往面临模型压缩工具链复杂、依赖环境配置繁琐等问题。本…

作者头像 李华
网站建设 2026/4/17 13:46:18

Window Resizer强力指南:突破窗口限制的智能解决方案

Window Resizer强力指南&#xff1a;突破窗口限制的智能解决方案 【免费下载链接】WindowResizer 一个可以强制调整应用程序窗口大小的工具 项目地址: https://gitcode.com/gh_mirrors/wi/WindowResizer 还在为应用程序窗口无法自由调整而困扰吗&#xff1f;Window Resi…

作者头像 李华