SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 267 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

For example,
this competing company might have a service that accesses your site, removes
advertisements and information that identify your organization, and displays
them to their customers. Or, they might have links to your site that are in framed
pages, thus making it appear that your page is part of their site. You??™d like to prevent
them from accessing certain pages at your site. However, every time their
Web hosting company boots them off, they simply change domain names and
register with another ISP. You thus want the ability to easily change the domain
names that should be banned.
The solution is to make a filter that uses initialization parameters to obtain a list of
banned sites. Requests originating or referred from these sites result in a warning
message. Other requests proceed normally. To accomplish this functionality, we
implement the following.
1. A class that implements the Filter interface. This class is called
BannedAccessFilter and is shown in Listing 5.12. The init
method of this class first obtains a list of sites from an initialization
parameter called bannedSites. The filter parses the entries in the
resultant String using the String.split method and stores each
individual site name in a HashSet that is accessible through an
Chapter 5 ?–  Servlet and JSP Filters 228
instance variable (i.e., field) of the filter. The String.split method
is supplied with the regular expression for one or more white space
characters to serve as the delimiter.


Pages:
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279