blogjava's web log

          blogjava's web log
          ...

          文件上傳

          cos文件上傳
          下載cos:http://www.servlets.com/cos/index.html
          把下的cos包加入工程
          新建jsp
          <%@?page?contentType="text/html;?charset=GBK"?%>
          <html>
          <head>
          <title>
          file
          </title>
          <script?lanuage=javascript>
          //文件后綴判斷
          ?function?isfile()
          {
          ???
          var?str=form1.file1.value.match(/^(.*)(\.)(.{1,8})$/)[3];
          ???
          //if(str!="jpg")
          ?????alert(form1.file1.value.match(/^(.*)(\.)(.{1,8})$/)[3]);

          ?
          //?else
          ?//?alert("其他");

          }

          </script>
          </head>
          <body?bgcolor="#ffffff">
          <h1>
          JBuilder?Generated?JSP
          </h1>
          <form?action="fileOK.jsp"?method="post"?enctype="multipart/form-data"?name="form1">
          ??上傳文件1:
          <input?type=file?onchange="isfile()"?id=file1><br?/>
          ??????文件描述1:
          <input?type="text"?name="file1"?size="40"/><br?/>
          <input??type="submit"?value="submit"?name="sub"?onclick="isfile()"/>
          </form>
          </body>
          </html>

          fileOK.jsp

          <%@?page?contentType="text/html;?charset=GBK"?%>
          <%@page?import="java.io.*,java.util.*"%>
          <%@page?import="com.oreilly.servlet.MultipartRequest"%>



          <html>
          <head>
          <title>
          fileOK
          </title>
          </head>
          <body?bgcolor="#ffffff">
          <h1>
          JBuilder?Generated?JSP
          </h1>
          ?
          <%
          ?try
          ?{
          ??
          //com.oreilly.servlet.multipart.e
          ???
          String?save?=?application.getRealPath("file")?+?"\\";
          ???out.print(save);
          ???com.oreilly.servlet.MultipartRequest??mr
          =new?com.oreilly.servlet.MultipartRequest(request,save,1000000,"gb2312");
          ??
          //MultipartRequest?mr1=new?MultipartRequest(
          ???Enumeration?files
          =mr.getFileNames();

          ???
          while(files.hasMoreElements())
          ???{
          ?????
          String?name=files.nextElement().toString();
          ?????out.print(
          "jsp1?name:"+name+"<br><hr>");
          ?????File?f
          =mr.getFile(name);
          ?????
          if(f!=null)
          ?????{
          ???????
          String?filename=mr.getFilesystemName(name);
          ????
          int?index=?filename.indexOf(".");
          ????
          //filename.lastIndexOf()
          ???out.print(filename.substring(index))??;
          ???????out.print(
          "<br>filename:"+filename+"<br><hr>");
          ???????
          String?lastname=save+filename;
          ???????out.print(
          "<br>上傳的文件"+lastname);
          ???????out.print(
          "<br><hr>");
          ?????}
          ???}

          ?}
          ?catch(Exception?ee)
          ?{
          ???out.print(
          "出錯了???"+ee.getMessage());
          ?}

          ??
          %>
          </body>
          </html>

          OK..

          posted on 2006-05-10 11:18 record java and net 閱讀(431) 評論(0)  編輯  收藏 所屬分類: Jsp&&Web

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 曲沃县| 宜宾市| 白城市| 台南市| 乌兰察布市| 涞源县| 柯坪县| 长治县| 江都市| 阜城县| 门源| 抚远县| 舞钢市| 永春县| 祁连县| 永寿县| 寻乌县| 前郭尔| 三台县| 齐河县| 资溪县| 汉沽区| 肇庆市| 扬中市| 合江县| 霍邱县| 腾冲县| 绍兴县| 黄平县| 长春市| 东平县| 盐池县| 天峻县| 乌兰察布市| 安丘市| 平武县| 珠海市| 龙山县| 翁源县| 东至县| 射阳县|