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:
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. CSV, XML and text-based Excel formats don't require a binary output, but if you want to try PDF, POI-based Excel, or some other custom binary format you may encounter problems.
The first attempt can be using a larger page buffer in your jsp pages, for example: <%@ page buffer = "16kb" %/> However, this can work only if you are in the first situation listed above.
In j2ee 1.3/jsp 1.2 containers, you can take advantage of filters to solve the problem. Displaytag ships with a filter that works together with the table tag during export, disallowing the flushing the response when 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 urls the filter 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>