table of contents
MSAJSP

Source Code Archive

More Servlets and JavaServer Pages


Chapter 9: Servlet and JSP Filters

To view source code for other chapters in this book, mouse over the table of contents bar on the left.

Source Code from Chapter

Note: right-click or shift-click on the links to download the associated file.

  • ReportFilter.java. Simple filter that prints a report on the standard output each time an associated servlet or JSP page is accessed.
  • web.xml. Deployment descriptor needed by all filters and filter-related examples in this Chapter.
  • index.jsp. Top-level page for filters-r-us.com. Requires the filter-styles.css style sheet and images in the images/ directory.
  • filter-styles.css. Style sheet used by most JSP pages in this Chapter.
  • TodaysSpecialServlet.java. Sample servlet used to test the simple filters.
  • RedirectorServlet.java. Servlet that simply redirects users to the Web application home page. Registered with the default servlet URL to prevent clients from using http://host/webAppPrefix/servlet/ServletName to bypass filters or security settings that are associated with custom URLs.
  • LogFilter.java. Filter that prints a report in the log file whenever the associated servlets or JSP pages are accessed.
  • LateAccessFilter.java. Filter that keeps track of accesses that occur at unusual hours.
  • BannedAccessFilter.java. Filter that refuses access to anyone connecting directly from or following a link from a banned site.
  • linker.html. A very simple page that contains little but a link to the daily special servlet. When that page is hosted on a normal site, the link results in the expected output. But, when the page that contains the link is hosted on a banned site, the link results only in a warning page--access to the real servlet is blocked.
  • CharArrayWrapper.java. A response wrapper that takes everything the client would normally output and saves it in one big character array.
  • ReplaceFilter.java. Filter that replaces all occurrences of a given string with a replacement. This is an abstract class: you must override the getTargetString and getReplacementString methods in a subclass. The first of these methods specifies the string in the response that should be replaced. The second of these specifies the string that should replace each occurrence of the target string.
  • FilterUtils.java. Small utility to assist with response wrappers that return strings.
  • ReplaceSiteNameFilter.java. A filter that replaces all occurrences of filtersRus.com with weBefilters.com. Subclass of the ReplaceFilter class.
  • page1.jsp. A page that promotes the filtersRus.com site name. Target of the ReplaceSiteNameFilter.
  • page2.jsp. A page that promotes the filtersRus.com site name. Identical to page1.jsp, but this page is the target of the ReplaceSiteNameFilter.
  • CompressionFilter.java. Filter that compresses output with gzip (assuming that browser supports gzip).
  • LongServlet.java. Servlet with long output. Used to test the effect of the compression filter.
  • filters.war. The entire filters application bundled in a WAR (Web ARchive) file.

URLs Referenced in Chapter

More Information

Java

JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts