<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)

    隨筆檔案

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产v亚洲v天堂a无| 国产精品免费观看调教网| 无套内射无矿码免费看黄| 男女作爱在线播放免费网站| 国产亚洲精久久久久久无码AV| 亚洲高清免费在线观看| 特级毛片aaaa级毛片免费| 1000部无遮挡拍拍拍免费视频观看 | 男人天堂2018亚洲男人天堂| 草久免费在线观看网站| 亚洲中文无码永久免费| 亚洲欧洲日本在线| 亚洲中文字幕久久精品无码A| 中文字幕手机在线免费看电影| 妞干网手机免费视频| 精品亚洲aⅴ在线观看| 韩国免费A级毛片久久| 亚洲av无码一区二区乱子伦as | 亚洲国产美女福利直播秀一区二区| 国产免费黄色无码视频| www国产亚洲精品久久久| 亚洲性色精品一区二区在线| 日韩免费电影在线观看| 中文字幕乱码亚洲无线三区| 国产日产成人免费视频在线观看| 亚洲av无码片在线观看| 91精品视频在线免费观看| 国产偷v国产偷v亚洲高清| 中文字幕无线码中文字幕免费| 亚洲最大成人网色| 免费黄色app网站| 亚洲国产成人AV在线播放| 成人免费在线视频| 亚洲人成人伊人成综合网无码 | 国产日韩久久免费影院| 亚洲视频一区在线| 亚洲伦乱亚洲h视频| 2019中文字幕在线电影免费| 亚洲爆乳AAA无码专区| 亚洲国产精品不卡在线电影| 无码日韩精品一区二区免费暖暖|