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 264 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

get(Calendar.HOUR_OF_DAY);
if (isUnusualTime(currentTime, startTime, endTime)) {
context.log("WARNING: " +
req.getRemoteHost() +
" accessed " +
req.getRequestURL() +
" on " +
formatter.format(calendar.getTime()));
}
chain.doFilter(request,response);
}
5.6 Example: An Access Time Filter 225
public void init(FilterConfig config)
throws ServletException {
this.config = config;
context = config.getServletContext();
formatter =
DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM);
try {
startTime =
Integer.parseInt(config.getInitParameter("startTime"));
endTime =
Integer.parseInt(config.getInitParameter("endTime"));
} catch(NumberFormatException nfe) { // Malformed or null
// Default: access at or after 10 p.m. but before 6 a.m.
// is considered unusual.
startTime = 22; // 10:00 p.m.
endTime = 6; // 6:00 a.m.
}
}
public void destroy() {}
// Is the current time between the start and end
// times that are marked as abnormal access times?
private boolean isUnusualTime(int currentTime,
int startTime,
int endTime) {
// If the start time is less than the end time (i.e.,
// they are two times on the same day), then the
// current time is considered unusual if it is
// between the start and end times.
if (startTime < endTime) {
return((currentTime >= startTime) &&
(currentTime < endTime));
}
// If the start time is greater than or equal to the
// end time (i.


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