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>

  • 相关阅读:
    使用Java实现对MySql数据库的导入与导出
    【转】揭开J2EE集群的神秘面纱
    Memcached深度分析
    HSQL入门及使用指南
    系统架构基础篇(高性能基础建设说明与选型条件)
    架构之美 摘抄
    JMS规范及相关实现
    spring3中使用@value注解获取属性值
    Thread Dump 分析综述
    什么中间件及中间件服务器?
  • 原文地址:https://www.cnblogs.com/belingzhong/p/2543406.html
Copyright © 2011-2022 走看看