Export filter? What's that?

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.
  • Something (tags? java snippets?) before the display:table tag has explicitely flushed the response (response.flushBuffer()).
  • Your page is dynamically included into another page. This happens for example using Struts tiles.

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 solution

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.

Installing the export filter

Configure the Filter in your web.xml:


And add mappings for urls the filter will intercept, for example: