# Response Filtering

Jetty provides a mechanism to allow filters to be conditionally inserted into the output stream of a response to a request. These filters, which are activated on content type, allow pages arbitrary changes to be made to responses that may have been generated, retrieved from a file or even fetched from another server (See forwarding). The class FilterHandler can be used to insert filters into a response, determined by the request path. Developers can extend com.mortbay.HTTP.HttpFilter to implement a filters. Jetty provides the utility filter com.mortbay.HTTP.Filter.HtmlFilter, which scans HTML responses for specially formatted HTML comments. These comments contain a call to a Java method on a class. Java reflection is used to find the class and static method and invoke the method with the given arguments. Static methods are also provided by com.mortbay.HTTP.Filter.HtmlFilter To include files or embed pages fetched from URLs. The source of this page is included below using com.mortbay.HTTP.Filter.HtmlFilter.includePreFile(). Other potential uses for filters include: Encryption and/or authentication with digital signatures Modification of link URLs for link tracking or page relocation. Embedding application specific dynamic content in authored HTML pages. Translation of formats not supported by a browser e.g. JPEG to GIF or EBSIDIC to ASCII.