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:
display:table
tag has explicitely flushed the response (
response.flushBuffer()
).
Another problem is related to exporting binary files. The output of binary data is not supported in jsps: it may work on some application server, but it may end up with errors in others. Because of this restriction an "external help" may be required. Cvs, xml and excel formats don't require a binary output, but if you want to try a pdf export or other custom binary formats you will have to face some problems.
The first attempt can be using a larger page buffer in your jsp pages, for example:
<%@ page buffer = "16kb" %>
In j2ee 1.3/jsp 1.2 containers you can take advantage of filters to solve the problem. Displaytag ships with a filter which works together with the table tag during export, disallowing the response to be flushed when an export has been requested.
Configure the Filter in your web.xml:
<filter>
<filter-name>ResponseOverrideFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>
And add mappings for the pages that you will intercept, for example:
<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>