split("\\s++");
for (String bannedSite: sites) {
bannedSiteTable.add(bannedSite);
System.out.println("Banned " + bannedSite);
}
}
public void destroy() {}
private String getReferringHost(String refererringURLString) {
try {
URL referringURL = new URL(refererringURLString);
return(referringURL.getHost());
} catch(MalformedURLException mue) { // Malformed or null
return(null);
}
}
Listing 5.12 BannedAccessFilter.java (continued)
Chapter 5 ?– Servlet and JSP Filters 232
// Replacement response that is returned to users
// who are from or referred here by a banned site.
private void showWarning(ServletResponse response,
String bannedSite)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
""Transitional//EN\">\n";
out.println
(docType +
"\n" +
"
Access Prohibited\n" +
"\n" +
"
Access Prohibited
\n" +
"Sorry, access from or via " + bannedSite + "\n" +
"is not allowed.\n" +
"");
}
}
Listing 5.13 web.xml (Excerpt for prohibited-site filter)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.
Pages:
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283