ExampleFilterpublic final class ExampleFilter extends Object implements FilterExample filter that can be attached to either an individual servlet
or to a URL pattern. This filter performs the following functions:
- Attaches itself as a request attribute, under the attribute name
defined by the value of the
attribute initialization
parameter.
- Calculates the number of milliseconds required to perform the
servlet processing required by this request, including any
subsequently defined filters, and logs the result to the servlet
context log for this application.
|
Fields Summary |
---|
private String | attributeThe request attribute name under which we store a reference to ourself. | private FilterConfig | filterConfigThe filter configuration object we are associated with. If this value
is null, this filter instance is not currently configured. |
Methods Summary |
---|
public void | destroy()Take this filter out of service.
// --------------------------------------------------------- Public Methods
this.attribute = null;
this.filterConfig = null;
| public void | doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)Time the processing that is performed by all subsequent filters in the
current filter stack, including the ultimately invoked servlet.
// Store ourselves as a request attribute (if requested)
if (attribute != null)
request.setAttribute(attribute, this);
// Time and log the subsequent processing
long startTime = System.currentTimeMillis();
chain.doFilter(request, response);
long stopTime = System.currentTimeMillis();
filterConfig.getServletContext().log
(this.toString() + ": " + (stopTime - startTime) +
" milliseconds");
| public void | init(javax.servlet.FilterConfig filterConfig)Place this filter into service.
this.filterConfig = filterConfig;
this.attribute = filterConfig.getInitParameter("attribute");
| public java.lang.String | toString()Return a String representation of this object.
if (filterConfig == null)
return ("InvokerFilter()");
StringBuffer sb = new StringBuffer("InvokerFilter(");
sb.append(filterConfig);
sb.append(")");
return (sb.toString());
|
|