• 单文件和批文件上传


    单文件上传

    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>

  • 相关阅读:
    linux-tar备份
    实验
    华为HCIA-命令及配置
    1、基本知识
    linux 安装samba
    POJ 2676 Sudoku (搜索,Dancing Links)
    HDU 1535 Invitation Cards (最短路,附SLF优化SPFA)
    ZOJ 3625 Geek's Collection (数学公式,注意long double输出格式,附输出格式总结)
    SGU 185 Two shortest (最大流)
    SPOJ PROFIT Maximum Profit (最大闭合权子图,最小割)
  • 原文地址:https://www.cnblogs.com/belingzhong/p/2543406.html
Copyright © 2020-2023  润新知