zoukankan      html  css  js  c++  java
  • Struts1.1实现文件上传

    <form-beans>
    <form-bean name="movevehicleCfgForm" type="com.huawei.agent.movevehicle.form.MovevehicleCfgForm" />
    </form-beans>

    <action name="movevehicleCfgForm" parameter="method" path="/move/movevehicle" type="org.springframework.web.struts.DelegatingActionProxy">
    <forward name="movevehicleImportShow" path="/mv/movevehicleImport.jsp" />
    </action>

      <form id="myForm" action="" method="post" enctype="multipart/form-data"style="margin-Top:0px;margin-Bottom:0px">

    <input type='file' name='filename' id='filename' value="浏 览"/>

    </form>

    if (file.getFileSize() > 0) {   // 判断是否有文件上传

        FileOutputStream out = null;

        try {

          byte[] b = file.getFileData();  // 取得文件数据

          String fileName = String.valueOf(Calendar.getInstance().getTimeInMillis());

          // 得到文件扩展名

          String extName = file.getFileName().substring(file.getFileName().lastIndexOf("."));

          File outfile = new File(dir + File.separator + fileName + extName);

          out = new FileOutputStream(outfile, false);

          out.write(b); // 通过流将数据写入文件

        } catch (Exception e) {

          e.printStackTrace();

        } finally {

          if (out != null) {

            try {

              out.close(); // 关闭文件输出流

            } catch (IOException e) {

              e.printStackTrace();

            }

          }

        }

      }

  • 相关阅读:
    天正暖通2013版安装包附带注册机下载
    你妈安好
    利用FLASH和XML做炫酷图片相册
    空调冷凝水管径选用原则
    知足常乐
    曾经的真三国无双
    Deep Exploration安装破解汉化
    Revit模型文件输出为3D PDF格式的方法
    Adobe Acrobat 9 Pro Extended简体中文版安装破解汉化教程
    Keep reading
  • 原文地址:https://www.cnblogs.com/lishoubin/p/3222163.html
Copyright © 2011-2022 走看看