<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Java學習

    java,spring,structs,hibernate,jsf,ireport,jfreechart,jasperreport,tomcat,jboss -----本博客已經搬家了,新的地址是 http://www.javaly.cn 如果有對文章有任何疑問或者有任何不懂的地方,歡迎到www.javaly.cn (Java樂園)指出,我會盡力幫助解決。一起進步

     

    用JSF和MyFaces上傳文件(2)——使用jsf中的inputFileUpload組件實現文件上傳下載

    <t:inputFileUpload id="fileupload" accept="WebContent/images/*"
    value="#{uploadCourse.learningpic}" storage="file"
    styleClass="fileUploadInput" required="true" />

    <h:panelGrid>
    <h:commandButton id="uploadButton" value="開始上傳"
    action="#{uploadCourse.upCourse}" type="submit" />
    </h:panelGrid>

    private UploadedFile learningpic;

    set() & get()

    public String upCourse() throws IllegalAccessException,
    InvocationTargetException, NoSuchMethodException ,IOException {
    Long a = new Long("1000000000000000");
    Double b = (a * Math.random());
    try {
    InputStream in = new BufferedInputStream(learningpic.getInputStream());
    try {
    byte[] buffer = new byte[64 * 1024];
    FileOutputStream fileOutputStream = new FileOutputStream("C:\\"+ b.toString() + ".jpg");
    while (in.read(buffer) > 0) {
    fileOutputStream.write(buffer);
    }
    } finally {
    in.close();
    }
    System.out.println("End");
    } catch (Exception e) {
    System.out.println("IOException");
    FacesMessage message = new FacesMessage(
    FacesMessage.SEVERITY_FATAL, e.getClass().getName(), e
    .getMessage());
    FacesContext.getCurrentInstance().addMessage(null, message);
    return "false";
    }


    UploadCourse uploadCourse = new UploadCourse();
    uploadCourse.setStatus("2");
    PropertyUtils.copyProperties(uploadCourse, this);

    if (uploadCourseService.upCourse(uploadCourse) == true) {
    return "success";
    } else {
    return "false";
    }

    }

    注意一定要在web.xml里加上filter,否則form將不能提交。
      <filter>
        <description>Set the size limit for uploaded files.
                Format: 10 - 10 bytes
                10k - 10 KB
                10m - 10 MB
                1g - 1 GB </description>
        <filter-name>extensionsFilter </filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter </filter-class>
        <init-param>
          <param-name>uploadMaxFileSize </param-name>
          <param-value>10m </param-value>
        </init-param>
        <init-param>
          <description>Set the threshold size - files
                    below this limit are stored in memory, files above
                    this limit are stored on disk.

                    Format: 10 - 10 bytes
                    10k - 10 KB
                    10m - 10 MB
                    1g - 1 GB </description>
          <param-name>uploadThresholdSize </param-name>
          <param-value>100k </param-value>
        </init-param>
      </filter>
      <filter-mapping>
      <filter-name>extensionsFilter </filter-name>
      <servlet-name>Faces Servlet </servlet-name>
      </filter-mapping>


    posted on 2008-10-28 16:02 找個美女做老婆 閱讀(1773) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    公告

    本blog已經搬到新家了, 新家:www.javaly.cn
     http://www.javaly.cn

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 91亚洲国产成人久久精品网站| 久久久久久亚洲精品不卡| 亚洲网站在线免费观看| 久久免费线看线看| 亚洲Av无码精品色午夜 | 亚洲成色WWW久久网站| 国产精品免费在线播放| 亚洲精品自在在线观看| 日韩电影免费观看| 亚洲综合久久1区2区3区| 我的小后妈韩剧在线看免费高清版| 久久精品九九亚洲精品| 67194国产精品免费观看| 亚洲免费黄色网址| 在线观看成人免费视频| 国产天堂亚洲国产碰碰| 亚洲精品尤物yw在线影院| 国产中文字幕在线免费观看| 亚洲国产精品人久久| 免费可以看黄的视频s色| 亚洲人AV在线无码影院观看| 免费女人18毛片a级毛片视频| 一级特黄录像免费播放肥| 亚洲AV永久无码精品水牛影视| 久久午夜伦鲁片免费无码| 亚洲一级视频在线观看| 丁香亚洲综合五月天婷婷| 成人一a毛片免费视频| 久久亚洲中文无码咪咪爱| 不卡精品国产_亚洲人成在线| 四虎影视成人永久免费观看视频| 亚洲乱人伦精品图片| 国产免费人成在线视频| 国精产品一区一区三区免费视频| 亚洲图片在线观看| 日本免费人成黄页网观看视频| 中文字幕免费观看全部电影| 亚洲图片中文字幕| 中文字幕不卡亚洲 | 中文字幕亚洲一区二区va在线| 免费不卡在线观看AV|