天空是藍色的

          做好軟件為中國 #gcc -c helloworld.c -o helloworld.o //編譯目標文件 #gcc helloworld.o -o helloworld //編譯成可執行exe #helloworld //運行exe
          數據加載中……
          運行上傳組件例子Upload Component

          創建3個文件
          UploadPage.java

            1import java.io.File;
            2import java.io.FileOutputStream;
            3import java.io.IOException;
            4import java.io.InputStream;
            5import java.text.Format;
            6import java.text.NumberFormat;
            7
            8import org.apache.tapestry.IRequestCycle;
            9import org.apache.tapestry.html.BasePage;
           10import org.apache.tapestry.request.IUploadFile;
           11
           12public class UploadPage extends BasePage {
           13    public static final Format SIZE_FORMAT = NumberFormat.getNumberInstance();
           14
           15    private IUploadFile file;
           16
           17    private File serverFile;
           18
           19    public IUploadFile getFile() {
           20        return file;
           21    }

           22
           23    public void setFile(IUploadFile value) {
           24        file = value;
           25    }

           26
           27    public String getFilename() {
           28        if (file != null{
           29            return file.getFileName();
           30        }
           else {
           31            return "";
           32        }

           33    }

           34
           35    public String getClientPath() {
           36        if (file != null{
           37            return file.getFilePath();
           38        }
           else {
           39            return "";
           40        }

           41    }

           42
           43    public String getServerPath() {
           44        if (serverFile != null{
           45            return serverFile.getAbsolutePath();
           46        }
           else {
           47            return "";
           48        }

           49    }

           50
           51    public long getFileSize() {
           52        if (serverFile != null{
           53            return serverFile.length();
           54        }
           else {
           55            return 0;
           56        }

           57    }

           58
           59    public boolean isFileTruncated() {
           60        if (file != null{
           61            return true;
           62            //修改過
           63        }
           else {
           64            return false;
           65        }

           66    }

           67
           68    public void formSubmit(IRequestCycle cycle) {
           69        InputStream fis = file.getStream();
           70        FileOutputStream fos = null;
           71
           72        try {
           73            fos = new FileOutputStream(new File(file.getFileName()));
           74            byte[] buffer = new byte[1024];
           75            while (true{
           76                int length = fis.read(buffer);
           77                if (length < 0{
           78                    break;
           79                }

           80                fos.write(buffer, 0, length);
           81            }

           82            fis.close();
           83            fos.close();
           84            serverFile = new File(file.getFileName());
           85
           86        }
           catch (IOException ioe) {
           87            ioe.printStackTrace();
           88        }
           finally {
           89            if (fis != null{
           90                try {
           91                    fis.close();
           92                }
           catch (IOException ioe) {
           93                }

           94            }

           95            if (fos != null{
           96                try {
           97                    fos.close();
           98                }
           catch (IOException ioe) {
           99                }

          100            }

          101        }

          102    }

          103
          104/****
          105    public static void main(String args[]) {
          106
          107    }
          108**/

          109    protected void initialize() {
          110        file = null;
          111        serverFile = null;
          112    }

          113}

          114

          UploadPage.page
           1<?xml version="1.0" encoding="UTF-8"?>
           2<!DOCTYPE page-specification PUBLIC
           3  "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
           4  "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
           5<!-- generated by Spindle, http://spindle.sourceforge.net -->
           6
           7<page-specification class="UploadPage">
           8
           9    <description>add a description</description>
          10    
          11    
          12    
          13</page-specification>

          UploadPage.html

           1<html>
           2<head>
           3</head>
           4<body>
           5<form jwcid="@Form" listener="ognl:listeners.formSubmit">
           6 <table bgcolor="#c0c0c0" cellpadding="4">
           7  <tr>
           8   <td colspan="2">File:&nbsp;<input jwcid="@Upload" file="ognl:file" type= "file"></input></td>
           9  </tr>
          10  <tr>
          11   <td colspan="2"><input type= "submit"value="Upload"></input></td>
          12  </tr>
          13  <tr>
          14   <td colspan="2"><hr></td>
          15  </tr>
          16  <tr>
          17   <td>Filename:</td><td><span jwcid="@Insert" value="ognl:filename"/></td>
          18  </tr>
          19  <tr>
          20   <td>Client path:</td><td><span jwcid="@Insert" value="ognl:clientPath"/></td>
          21  </tr>
          22  <tr>
          23   <td>Server Path:</td><td><span jwcid="@Insert" value="ognl:serverPath"/></td>
          24  </tr>
          25  <tr>
          26   <td>File Truncated:</td><td><span jwcid="@Insert" value="ognl:fileTruncated"/></td>
          27  </tr>
          28  <tr>
          29   <td>File Size:</td><td><span jwcid="@Insert" value="ognl:fileSize" format="ognl:@UploadPage@SIZE_FORMAT"/>&nbsp;bytes</td>
          30  </tr>
          31 </table>
          32</form>
          33</body>
          34</html>

          posted on 2005-11-09 10:48 bluesky 閱讀(618) 評論(0)  編輯  收藏 所屬分類: 框架應用

          主站蜘蛛池模板: 田林县| 且末县| 开鲁县| 武清区| 中西区| 岑溪市| 内乡县| 肃南| 株洲市| 浮山县| 昌吉市| 固安县| 凤台县| 南江县| 绥滨县| 安福县| 封开县| 渝中区| 赞皇县| 灵寿县| 共和县| 疏附县| 霍城县| 卢龙县| 开阳县| 肇庆市| 通榆县| 大英县| 林口县| 宽甸| 朝阳区| 佛冈县| 青浦区| 麟游县| 永顺县| 舟山市| 鄄城县| 静宁县| 平遥县| 锡林郭勒盟| 垣曲县|