关于displaytag的列表不能导出Excel的问题

关键字: displaytag
关于displaytag的列表不能导出Excel的问题,已经弄清楚原因并找到解决方案了。
异常堆栈:
Exception: [.ELTableTag] Unable to reset response before returning exported data. You are not using an export filter. Be sure that no other jsp tags are used before display:table or refer to the displaytag documentation on how to configure the export filter (requires j2ee 1.3).
at org.displaytag.tags.TableTag.writeExport(TableTag.java:1275)
at org.displaytag.tags.TableTag.doExport(TableTag.java:1201)
at org.displaytag.tags.TableTag.doEndTag(TableTag.java:1070)
……

原因:未使用displaytag的导出过滤器(org.displaytag.filter.ResponseOverrideFilter),不过这在通常情况下并不会导致问题,但是如果在JSP的页面中使用了其它框架的标签(诸如Struts),而非常巧合的是在这些标签的处理过程中又恰好调用了ServletResponse.flushBuffer()等可以导致提交响应(即导致ServletResponse.isCommit()返回true)的方法,这个问题就会出现。
解决方案:配置Displaytag的导出过滤器(web.xml)。
Xml代码
<filter> 
      <filter-name>ResponseOverrideFilter</filter-name> 
      <filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class> 
  </filter> 
…… 
<filter-mapping> 
      <filter-name>ResponseOverrideFilter</filter-name> 
      <url-pattern>*.do</url-pattern> 
</filter-mapping> 
<filter-mapping> 
      <filter-name>ResponseOverrideFilter</filter-name> 
      <url-pattern>*.jsp</url-pattern> 
</filter-mapping> 
默认情况下此过滤器在把导出内容写回响应之前会将这些内容进行缓存。我们也可以设置一个可选的参数(buffer)的值为false以便使过滤器直接把内容写到输出流中,这可以使响应速度更快并且使用更少的内存,但是内容的长度不会被设置。在这里我们不设置这个参数。
原文地址:http://zuiyanwangyue.iteye.com/blog/359778

还有另外一种解决方案:
Context :
When displaytag exports data in any non-html format, it needs to change the content type returned to the browser and reset any other content generated by the surrounding page.
Sometimes this can’t be done: if content has already been sent back to the user, the response can’t be reset and you get an error. This could happen because too many chars have been already written to the response, so that the response buffer was full and response has been automatically flushed.
Solution :
Add the following to the page…
<%@ page buffer = "16kb" %>
原文地址:http://ibnaziz.wordpress.com/2008/09/03/exception-tabletag-unable-to-reset-response-before-returning-exported-data/

   经检验,后一个方法好像不行。

你可能感兴趣的:(jsp,xml,struts,Excel,wordpress)