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

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

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

    cuiyi's blog(崔毅 crazycy)

    記錄點滴 鑒往事之得失 以資于發(fā)展
    數(shù)據(jù)加載中……

    論技術(shù)官方似乎確比民間友好,jstl之c:import之惑(二)

    論技術(shù)官方似乎確比民間友好,strust之bean:include之感(一)
    論技術(shù)官方似乎確比民間友好,jstl之c:import之感(二)

    上篇文章“論技術(shù)官方似乎確比民間友好,struts之bean:include之感(一)”中分析了struts的bean:include的不足;
    用c:import似乎是個比較完善的解決方案;
    然而一物終降一物,工程應(yīng)用的復(fù)雜,必然引出新的挑戰(zhàn),本文主要分析c:import的困惑


    Exception
    IllegalStateException: Cannot forward after response has been committed

    Exception情景

    1)在Servlet1中用forward轉(zhuǎn)向jsp1頁面,然后JSP1的頁面有一個鏈接,這個連接指向Servlet2,然后Servlet2再用forward轉(zhuǎn)向jsp2
    2)Action1
         mapping.find("a.jsp")

         a.jsp
         <c:import url="b.do?method=doB&id=aid">

    Reason

    遇到Cannot forward after response has been committed,是由于有頁面顯示后仍然含請求轉(zhuǎn)向產(chǎn)生的,而當(dāng)頁面有輸出之后是不能夠重定向的,同理還適用于  
      repsonse.sendRedirect();  
      <jsp:forward   page=""/>

    至于<c:import>造成的IllegalStateException: Cannot forward after response has been committed原因
    是因為某些時候Action的資料量太大,超出JSP默認的8kb,就會被迫使先把response傳給使用者,這也就早晨管理其他資料沒有辦法完全傳遞過來,傳遞過來的時候響應(yīng)已經(jīng)做出了

    Reference

    Hans's Top Ten JSP TipsDealing with Buffer Flushing Issues

    An HTTP response message contains both headers and a body. The headers tell the browser things like what type of data the body contains (HTML text, an image), the size of the body, if the body can be cached, and so on. Headers are also used to set cookies and to tell the browser to automatically get another page (a redirect). All response headers must be sent to the browser before the body is sent.

    To allow parts of the body to be produced (from static template text as well as content generated dynamically by JSP elements) before headers are set, the body is buffered. Instead of sending the response to the browser as soon as something is written to the response body, the JSP container writes all static markup code and all dynamic content generated by JSP elements to the buffer. At some point, such as when the buffer is full or the end of the page is reached, the container sends all headers that have been set followed by the buffered body content. In servlet speak, this is called committing the response. After the response has been committed, you can't set headers, such as for cookies or a redirection instruction. Another thing you can't do is forward the request to another page.

    In most cases, this is not a problem. The default buffer size is 8KB, more than enough for a typical page, and you can increase it with the buffer attribute of the page directive. But if you use the include action in a page, you may be in for a surprise. Due to limitations in the way the servlet features used by <jsp:include> are specified, the buffer is always flushed before the target page is invoked. This means that you can't set headers or use <jsp:forward> after a <jsp:include> action.

    An unfortunate side-effect of this automatic flushing is that runtime errors triggered by JSP elements after a <jsp:include> action may not be reported correctly, since many JSP containers use the forward mechanism to display the error page. If you see an error message like "response already committed" in a page with <jsp:include> elements, I suggest that you use the include directive instead (at least until you have isolated the problem).

    Hans's Top Ten JSP TipsChoosing the Right Include Mechanism

    A JSP page can include page fragments from other files to form the complete response. You can use this, for instance, to keep header, footer, and navigation bar content in separate files and include them in all other pages. There are two include mechanisms: the include directive and the include action. It's not always obvious which one to use, though.

    The include directive, <%@ include file="filename.inc" %>, includes the content of the specified file during the translation phase--when the page is converted to a servlet. The main page and the included file are simply merged. This means that scripting variables declared in one file (using scripting elements or an action element like <jsp:useBean>) are visible in all files and must have unique names. Some containers detect changes in files included with the directive, but the specification doesn't require it. Therefore, changes you make to the included file in a running system may not be reflected immediately; you may have to update the main JSP page, or remove the class file generated for the main page in order to see the change.

    The include action, <jsp:include page="pagename.jsp" flush="true" />, includes the response generated by executing the specified page (a JSP page or a servlet) during the request processing phase--when the page is requested by a user. As opposed to the include directive, the page name can be specified as a so-called request-time attribute value, so which page to include can be decided when the main page is requested. Since it's the response generated by the page that is included, not the content of the page itself, scripting variables declared in one file are not available to the other files. To share an object between the pages you must instead place it in one of the following JSP scopes: request, session or application scope. If you change a page included with the include action, the change always takes effect immediately.

    My rule of thumb for when to use the different mechanisms is this:

    o    Use the include directive if the file changes rarely. It's the fastest mechanism. If your container doesn't automatically detect changes, you can force the changes to take effect by deleting the main page class file.

    o    Use the include action only for content that changes often, and if which page to include cannot be decided until the main page is requested.

    Solution

    1) 加大jsp buff

     How<%@ page buffer="16kb" %>

    Doubt: what would be if the infos size larger than specified buffer? No problem, 8k is enough for one page

    2) absolute path

    Would make context imported part independence of the caller context;就是說<c:import>引入的內(nèi)容和當(dāng)前整個頁面的上下文并不完全一樣。

    3) 若為Servlet類
    解決辦法,在request.getRequestDispatcher("*.jsp").forward(request, response);后加return;OK

    4)若URL里沒有變量,用<%@ page=''%>即可




    posted on 2007-11-15 19:11 crazycy 閱讀(3771) 評論(0)  編輯  收藏 所屬分類: JavaEE技術(shù)

    主站蜘蛛池模板: 免费人成网站在线观看10分钟| a毛片免费全部在线播放**| 亚洲精品免费在线视频| 亚洲色爱图小说专区| a级毛片免费观看视频| 久久亚洲色一区二区三区| 美女无遮挡拍拍拍免费视频 | 久久久无码精品亚洲日韩按摩| a毛片全部播放免费视频完整18| 久久久久久A亚洲欧洲AV冫| 国产精品玖玖美女张开腿让男人桶爽免费看 | 日本黄色免费观看| 激情婷婷成人亚洲综合| 亚洲av无码成人精品区| 久久久久久久国产免费看| 亚洲一级二级三级不卡| 国产成人免费午夜在线观看 | 羞羞视频网站免费入口| 国产成人99久久亚洲综合精品 | 岛国av无码免费无禁网站| 亚洲日韩一区二区一无码| 国产在线19禁免费观看国产| 一区二区三区在线观看免费| 国产AV无码专区亚洲AV男同| 久久久久久精品免费免费自慰| 亚洲综合在线一区二区三区| 亚洲AⅤ优女AV综合久久久| 国产在线国偷精品免费看| 亚洲毛片免费观看| 凹凸精品视频分类国产品免费| av网站免费线看| 亚洲成aⅴ人片在线影院八| 国产大片91精品免费看3| 91视频免费观看高清观看完整| 亚洲男人电影天堂| 亚洲av午夜精品一区二区三区| 日本一区二区免费看| 亚洲人成色在线观看| 国产精品亚洲片在线观看不卡| 毛片免费观看的视频在线| 十八禁在线观看视频播放免费|