zoukankan      html  css  js  c++  java
  • 单文件和批文件上传

    单文件上传

    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>

  • 相关阅读:
    软件设计师2006年11月下午试题6(C++ 状态模式)
    Delphi中使用RegExpr单元进行匹配与替换操作
    正则表达式中贪婪与懒惰匹配
    C++类属性算法equal和mismatch
    lazarus下使用正则表达式
    正则表达式在每行开头插入行号
    STL向量构造函数
    软件设计师2004年5月下午试题6(C++ 数组下标检测)
    演示STL双端队列的push_back和push_front函数
    用正则表达式改小写为大写
  • 原文地址:https://www.cnblogs.com/belingzhong/p/2543406.html
Copyright © 2011-2022 走看看