OC4J上有一個JSP,
指令是<fmt:formatNumber value="${valueMap[yearQKey]}" groupingUsed="true" />
使用fmt:

formatNumber把hashmap內BigDecimal grouping
以往一直都很正常,某天突然發生一個能100% reproduce的Exception

Stack trace在本文最下方,
google查了一下資料,
網路上對Response is already committed這個exception並沒有明確的解法
2012/08/18 更新 : Oracle Forums article 指出原因和解法,只要增加page buffer size即可。
由stack trace來看應該是fmt做完份內事之後,
再做fmt.SetLocaleSupport.getFormattingLocale和fmt.SetLocaleSupport.setResponseLocale
的時候出了問題

第一個想法是這個exception訊息看來似乎跟執行速度有關
出問題的資料是 "0", "0", "0", "0", "0", "0", "12", "0", "0", "12",到第5個0之後就發生exception
以往的資料都是上萬,卻未曾發生這個問題
簡單的資料出問題,複雜的沒問題,這樣看來又似乎跟執行速度沒有關係?

實在想不出原因,只好先多方嘗試,或許減少使用fmt或加速fmt可以改善?
1.
提問:如果是0造成的,那只要是0就不使用fmt
 <c:choose>
     <c:when test="${0 == value}">0
     </c:when>
     <c:otherwise>
         <fmt:formatNumber value="${valueMap[yearQKey]}" groupingUsed="true" />
     </c:otherwise>
 </c:choose>
結論:依然在第5個0之後發生exception,完全不合理,因為0不使用fmt
2.
提問:究竟when有沒有正常運作?
 <c:choose>
     <c:when test="${0 == value}">0.0
     </c:when>
     <c:otherwise>
         <fmt:formatNumber value="${valueMap[yearQKey]}" groupingUsed="true" />
     </c:otherwise>
 </c:choose>
結論:確實顯示0.0,代表when的設定正確,且exception不再發生!
     七月都還沒到,這是怎麼了?
     user不接受0.0,必須另尋方法
3.
提問:是什麼原因讓0.0能避開exception,於是測試"A", "A.A", " 0", "0 "
結論:都會發生exception
4.
提問:有沒有可能不是太慢而是太快?
 <c:choose>
     <c:when test="${0 == value}">0<div></div>
     </c:when>
     <c:otherwise>
         <fmt:formatNumber value="${valueMap[yearQKey]}" groupingUsed="true" />
     </c:otherwise>
 </c:choose>
結論:exception不再發生!另一個驚人的現象
5.
提問:在那邊新增div,接手maintain的人八成會刪掉,等於是個未爆彈
 <c:set var="value" value="${valueMap[yearQKey]}"/>
 <c:choose>
     <c:when test="${empty value or 0 == value}">0
     </c:when>
     <c:otherwise>
         <fmt:formatNumber value="${value}" groupingUsed="true" />
     </c:otherwise>
 </c:choose>
結論:exception不再發生!
雖然沒有任何肯定的成因推論,而且測試結果非常不理性
能解決問題,就是好方法,決定採用此解!

Stacktrace如下
java.lang.IllegalStateException: Response is already committed!
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.EvermindHttpServletResponse.setLocale(EvermindHttpServletResponse.java:1809)
       at org.apache.taglibs.standard.tag.common.fmt.SetLocaleSupport.setResponseLocale(SetLocaleSupport.java:200)
       at org.apache.taglibs.standard.tag.common.fmt.SetLocaleSupport.getFormattingLocale(SetLocaleSupport.java:282)
       at org.apache.taglibs.standard.tag.common.fmt.FormatNumberSupport.doEndTag(FormatNumberSupport.java:167)
       at _???._????._????._jspService(_????????.java:661)
       [SRC:/???/????/????????.jsp:99]
       at com.orionserver[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
       at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:567)
       at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:302)
       at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
       at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:810)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:220)
       at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:111)
       at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
       at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:965)
       at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:744)
       at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
       at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
       at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
       at com.vis.crm.filter.CrmUserProfileFilter.doFilter(CrmUserProfileFilter.java:70)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:16)
       at com.vis.crm.filter.CrmUserFilter.doFilter(CrmUserFilter.java:77)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:645)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.AJPRequestHandler.run(AJPRequestHandler.java:208)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].server.http.AJPRequestHandler.run(AJPRequestHandler.java:125)
       at com.evermind[Oracle Application Server Containers for J2EE 10g
(10.1.2.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
       at java.lang.Thread.run(Thread.java:534)
創作者介紹

Jason Lin 的資料庫

jsdb 發表在 痞客邦 PIXNET 留言(0) 人氣()