基于jspSmartUpload的JSP文件上传(一次可以上传多个文件)

可以一次上传多个文件

upload.html

<html>
<head>
<title>网页设计:文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p>&nbsp;</p>
<p align="center">上传文件选择</p>
<FORM METHOD="POST" ACTION="do_upload.jsp" ENCTYPE="multipart/form-data">
<input type="hidden" name="TEST" value="good">
  <table width="75%" border="1" align="center">
    <tr> 
      <td><div align="center">1、 
          <input type="FILE" name="FILE1" size="30">
        </div></td>
    </tr>
    <tr> 
      <td><div align="center">2、 
          <input type="FILE" name="FILE2" size="30">
        </div></td>
    </tr>
    <tr> 
      <td><div align="center">3、 
          <input type="FILE" name="FILE3" size="30">
        </div></td>
    </tr>
    <tr> 
      <td><div align="center">4、 
          <input type="FILE" name="FILE4" size="30">
        </div></td>
    </tr>
    <tr> 
      <td><div align="center">
          <input type="submit" name="Submit" value="上传它!">
        </div></td>
    </tr>
  </table>
</FORM>
</body>
</html>

do_upload.jsp

<%@ page contentType="text/html; charset=gb2312"  import="com.jspsmart.upload.SmartUpload"  %>
<html>
<head>
<title>中国网页设计:文件上传处理页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
<%
 SmartUpload su = new SmartUpload();
 su.initialize(pageContext); // 上传初始化
 su.upload(); // 上传文件
 int count = su.save("/upload");
 out.println(count+"个文件上传成功!<p />"); 
 // 逐一提取上传文件信息,同时可保存文件。
 for (int i=0;i<su.getFiles().getCount();i++)
 {        com.jspsmart.upload.File file = su.getFiles().getFile(i);
 // 若文件不存在则继续
  if (file.isMissing()) continue;
  
  // 显示当前文件信息
  out.println("文件长度(Size):" + file.getSize() + "<br />");
  out.println("文件名(FileName):" +  file.getFileName() + "<br />");
     out.println("文件扩展名(FileExt):" +  file.getFileExt());
  out.print("<br>___________________________<br>");
  
 }
%>

</body>
</html>

125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/2923.html

(0)
江山如画的头像江山如画管理团队
上一篇 2018年12月11日 下午3:14
下一篇 2018年12月11日 下午3:26

99%的人还看了以下文章

  • 第六章 Servlet技术(重点章节)

    学习目标:
    掌握Servlet的概念、特点及生命周期
    掌握Servlet与JSP的区别
    理解Servlet在Web项目中的作用
    掌握Servlet常用对象及其方法

    2018年2月22日
    4.7K0
  • JSP分页思想—核心代码

    try{condition=”select * from employee_info”; sql=conn.createStatement(); rs=sql.executeQuery(condition); int intPageSize; //一页显示的记录数 int intRowCount; //记录总数 int intPageCount; //总页数…

    2019年10月30日
    4.3K0
  • Python编程入门:英文词频统计

    text = “Got tho on super sale. Love it! Cuts my drying time in half Reckon I have had this about a year now,\ at least 7 months. Works great, I use it 5 days a week, blows hot air,…

    2023年10月3日
    7.0K0
  • 第一个Spring MVC 项目:Hello World(Eclipse版)

    125建站网前面分享了《Spring框架概述》,新学习的同学可以先阅读引文章,今天给大家分享第一个Spring MVC实战项目:Hello World 目录  一、MVC概要 二、Spring MVC介绍 三、第一个Spring MVC 项目:Hello World(Eclipse版) 3.1、通过Maven新建一个Web项目 3.2、添加依赖的jar包 3…

    2023年1月24日 编程开发
    9240
  • 上机三 Java Web应用程序设计

    建议学时:8 2学时 一、编写JSP页面date.jsp,格式化显示系统当前时间 需要使用Date类和SimpleDateFormat类。 在头部引入。 <%@ page import=”java.util.Date”%> <%@ page import=”java.text.SimpleDateFormat”%> SimpleDat…

    2018年9月11日
    18.8K1
  • JSP分页思想2—核心代码

    一、通过order by id desc limit ?,? 控制当前页面显示的记录 显示第几页,共几页,上一页 下一页 <% int PageSize=2; //一页显示的记录数 int RowCount=0; //记录总数 int PageCount=0; //总页数 int intPage; //待显示页码 int i;//循环变量 String…

    2019年10月30日
    11.3K0

发表回复

登录后才能评论