紙飛機

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            22 隨筆 :: 28 文章 :: 30 評論 :: 0 Trackbacks

          2007年7月9日 #

          用jspsmart下載文件異常(tomcat正常,weblogic不行)

          用jspsmart下載文件JSP代碼如下:
          <%@ page contentType="text/html;charset=GBK" import="com.jspsmart.upload.*" %><%
          //取得服務器存放文件的路徑
          String reportTemplatePath = (String)session.getAttribute("reportTemplatePath");
          //文件名
          String filename = reportTemplatePath + "/" + request.getParameter("filename");
          filename = new String(filename.getBytes(),"ISO-8859-1");
          // 新建一個SmartUpload對象
          SmartUpload su = new SmartUpload();
          // 初始化
          su.initialize(pageContext);
          //設定contentDisposition為null以禁止瀏覽器自動打開文件,保證點擊鏈接后是下載文件。若不設定,則下載的文件擴展名為
          //doc時,瀏覽器將自動用word打開它。擴展名為pdf時,瀏覽器將用acrobat打開。
          su.setContentDisposition(null);
          // 下載文件
          su.downloadFile(filename);
          %>在tomcat中運行正常。
          在weblogic中運行拋出如下異常.
          文件可以下載,但特別慢并且打開是亂碼。
          <2004-2-19 下午09時14分34秒> <Error> <HTTP> <101019> <[ServletContext(id=325867,
          name=csrc,context-path=/csrc)] Servlet failed with IOException
          java.net.ProtocolException: Exceeded stated content-length of: '548352' bytes
                  at weblogic.servlet.internal.ServletOutputStreamImpl.checkCL(ServletOutp
          utStreamImpl.java:220)
                  at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutput
          StreamImpl.java:170)
                  at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:986)
                  at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:355)
                  at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:336)
                  at jsp_servlet._test.__do_download._jspService(__do_download.java:102)
                  at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
                  at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
          (ServletStubImpl.java:1058)
                  at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
          pl.java:401)
                  at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
          pl.java:306)
                  at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
          n.run(WebAppServletContext.java:5445)
                  at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
          eManager.java:780)
                  at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
          rvletContext.java:3105)
                  at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
          pl.java:2588)
                  at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
                  at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
          >

          解決方法:把所有<%和%>之外的空格字符都取掉就好了.參考如下:
          <%@ page contentType="text/html;charset=GBK" import="com.jspsmart.upload.*" %><%
          //取得服務器存放文件的路徑
          String reportTemplatePath = (String)session.getAttribute("reportTemplatePath");
          //文件名
          String filename = reportTemplatePath + "/" + request.getParameter("filename");
          filename = new String(filename.getBytes(),"ISO-8859-1");
          // 新建一個SmartUpload對象
          SmartUpload su = new SmartUpload();
          // 初始化
          su.initialize(pageContext);
          //設定contentDisposition為null以禁止瀏覽器自動打開文件,保證點擊鏈接后是下載文件。若不設定,則下載的文件擴展名為
          //doc時,瀏覽器將自動用word打開它。擴展名為pdf時,瀏覽器將用acrobat打開。
          su.setContentDisposition(null);
          // 下載文件
          su.downloadFile(filename);
          %>

           

          posted @ 2008-06-02 16:04 紙飛機 閱讀(3801) | 評論 (2)編輯 收藏

          GBK的文字編碼是雙字節來表示的,即不論中、英文字符均使用雙字節來表示,只不過為區分中文,將其最高位都定成1。

          至于UTF-8編碼則是用以解決國際上字符的一種多字節編碼,它對英文使用8位(即一個字節),中文使用24位(三個字節)來編碼。對于英文字符較多的論壇則用UTF-8節省空間。

          GBK包含全部中文字符,
          UTF-8則包含全世界所有國家需要用到的字符。

          GBK是在國家標準GB2312基礎上擴容后兼容GB2312的標準(好像還不是國家標準)

          UTF-8編碼的文字可以在各國各種支持UTF8字符集的瀏覽器上顯示。
          比如,如果是UTF8編碼,則在外國人的英文IE上也能顯示中文,而無需他們下載IE的中文語言支持包。

          所以,對于英文比較多的論壇 ,使用GBK則每個字符占用2個字節,而使用UTF-8英文卻只占一個字節。

          請注意:UTF-8版本雖然具有良好的國際兼容性,但中文需要比GBK/BIG5版本多占用50%的數據庫存儲空間,因此并非推薦使用,僅供對國際兼容性有特殊要求的用戶使用。</DIV>
          簡單地說:
                 對于中文較多的論壇,適宜用GBK編碼節省數據庫空間。
                 對于英文較多的論壇,適宜用UTF-8節省數據庫空間。

          posted @ 2008-05-22 14:07 紙飛機 閱讀(450) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2008-05-15 21:41 紙飛機 閱讀(654) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-26 13:48 紙飛機 閱讀(552) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-26 13:47 紙飛機 閱讀(1454) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-26 13:45 紙飛機 閱讀(314) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-26 13:40 紙飛機 閱讀(356) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-26 13:38 紙飛機 閱讀(704) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-24 23:38 紙飛機 閱讀(295) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-23 10:10 紙飛機 閱讀(655) | 評論 (0)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-10-21 23:45 紙飛機 閱讀(4742) | 評論 (5)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-07-20 15:44 紙飛機 閱讀(5183) | 評論 (2)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-07-19 22:41 紙飛機 閱讀(2054) | 評論 (3)編輯 收藏

               摘要:   閱讀全文
          posted @ 2007-07-19 10:14 紙飛機 閱讀(6712) | 評論 (0)編輯 收藏

          最近在學習Hibernate這個框架,有找到一個比較好的資料,作者的blog名是分享Java快樂
          website:http://blog.csdn.net/javamxj/
          我有將其資料制作成chm電子檔,這樣學習起來比較方便,需要的朋友可通過如下鏈接下載:

           http://www.aygfsteel.com/Files/jxhkwhy/Eclipse快速上手Hibernate.rar

          另以上的例子我都有重新做過一遍,期間也碰到不過問題,如果學習的朋友碰到問題可找我,我一定會盡力回復!

           

          posted @ 2007-07-09 00:22 紙飛機 閱讀(1236) | 評論 (5)編輯 收藏

          主站蜘蛛池模板: 庆城县| 桃江县| 永昌县| 宜州市| 丰城市| 绥阳县| 成武县| 西盟| 沈丘县| 安阳县| 买车| 亳州市| 珠海市| 中西区| 集安市| 日照市| 吉隆县| 冀州市| 永修县| 启东市| 金华市| 望江县| 英山县| 武平县| 苏尼特右旗| 永胜县| 潞西市| 保康县| 辽源市| 澳门| 漠河县| 沾化县| 康保县| 旅游| 错那县| 和林格尔县| 涞源县| 兴安县| 贡山| 铜陵市| 余干县|