export_filter.apt

来自「分页标签」· APT 代码 · 共 72 行

APT
72
字号
                                    ------------------------------                                            Export filter                                    ------------------------------                                          Fabrizio Giustina                                    ------------------------------                                              26-11-2005                                    ------------------------------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 injsps: it may work on some application server, but it may end up with errors in others. Because of thisrestriction an "external help" may be required. CSV, XML and text-based Excel formats don't require a binaryoutput, but if you want to try PDF, POI-based Excel, or some other custom binary format you may encounterproblems.* 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:+--------------------------------------------------------+  <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>+--------------------------------------------------------+

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?