• 单文件和批文件上传


    单文件上传

    smartupload_demo01.htm

    <html>
    <head><title>www.mldnjava.cn,MLDN高端Java培训</title></head>
    <body>
    <form action="smartupload_demo01.jsp" method="post" enctype="multipart/form-data">
     请选择要上传的文件:<input type="file" name="pic">
     <input type="submit" value="上传">
    </form>
    </body>
    </html>

     smartupload_demo01.jsp

    <%@ page contentType="text/html" pageEncoding="GBK"%>
    <%@ page import="org.lxh.smart.*"%>
    <html>
    <head><title>www.mldnjava.cn,MLDN高端Java培训</title></head>
    <body>
    <%
     SmartUpload smart = new SmartUpload() ;
     smart.initialize(pageContext) ; // 初始化上传操作
     smart.upload() ;   // 上传准备
     smart.save("upload") ; // 文件保存
    %>
    </body>
    </html>

    批量文件上传

    smartupload_demo03.htm

    <html>
    <head>
    <title></title>
    </head>
    <body>
      <form action = "smartupload_demo03.jsp" method = "post" enctype = "multipart/form-data">
      照片1:<input type = "file" name = "pic"><br>
      照片2:<input type = "file" name = "pic"><br>
      照片3:<input type = "file" name = "pic"><br>
      <input type = "submit" value = "上传">
      <input type = "reset" value = "重置">
      </form>
    <body>
    </html>

    smartupload_demo03.jsp

    <%@ page contentType = "text/html" pageEncoding = "GBK"%>
    <%@ page import = "org.lxh.smart.*"%>
    <%@ page import = "cn.mldn.lxh.util.IPTimeStamp"%>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <%
      request.setCharacterEncoding("GBK");//解决乱码
    %>
    <%
       SmartUpload smart = new SmartUpload();//实例化SmartUpload上传组件
       smart.initialize(pageContext);//初始化上传操纵
       smart.upload();  //上传准备
       IPTimeStamp its = new IPTimeStamp(request.getRemoteAddr());//实例化IPTimeStamp对象
       for(int x=0;x<smart.getFiles().getCount();x++){
          String ext = smart.getFiles().getFile(x).getFileExt();//取得文件后缀
       String fileName = its.getIPTimeRand()+"."+ext;//拼凑文件名称
       smart.getFiles().getFile(x).saveAs(getServletContext().getRealPath("/")+"upload"+java.io.File.separator+fileName);//保存文件
       }

    %>
    </body>
    </html>

  • 相关阅读:
    centos软件安装
    新手根据菜鸟教程安装docker,从No package docker-io available开始遇到的坑...
    性能基准测试:KVM大战Xen
    Netdata---Linux系统性能实时监控平台部署记录
    Linux Storage Stack Diagram存储堆栈图
    /proc目录下文件详解
    磁盘IO计算
    RPM包下载网址
    搜索框获取转移焦点事件
    用点击事件做红绿灯2
  • 原文地址:https://www.cnblogs.com/belingzhong/p/2543406.html
Copyright © 2020-2023  润新知