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

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

30 RequestCounter.java (continued)
6.12 Example: Calculating Server Request Load 319
// Calculate ration of requests per second
double ratio = totalRequests / (double) totalSeconds;
ratio = ((int)(ratio * 100) / (double) 100);
// Populate RequestStats bean;
// store it in the request scope and
// forward it to stats page
RequestStatsBean requestStats =
new RequestStatsBean(totalSeconds, totalRequests, ratio);
request.setAttribute("stats", requestStats);
RequestDispatcher dispatcher =
request.
getRequestDispatcher("/WEB-INF/pages/req-stats.jsp");
dispatcher.forward(request, response);
}
}
Listing 6.32 req-stats.jsp



Request Frequency Statistics
HREF="events-styles.css"
TYPE="text/css">



Request Frequency Statistics



  • Total number of requests in the life of this
    Web application: ${stats.totalRequests}.
  • Web application has been up for
    ${stats.totalSeconds} seconds.
  • This means that our request load is about
    ${stats.ratio} requests per second.


Listing 6.31 ProcessRequestStats.java (continued)
Chapter 6 ?–  The Application Events Framework 320
Listing 6.33 RequestStatsBean.java
package coreservlets;
/** Bean used to store the collected request frequency data.


Pages:
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373