Chapter 16

Filters, MVC, and Ajax

IN THIS CHAPTER

  • Working with filters
  • Creating an Ajax password filter
  • Creating an Ajax logging filter
  • Creating an Ajax time-of-day filter
  • Creating an Ajax-enabled Model-View-Controller application

This chapter covers some advanced Ajax techniques: using filters and model-view-controller (MVC) architecture.

You can use filters with Ajax to restrict access to resources on the server. Filters can get control of the user's request before that request is passed on to the Web resource the user is trying to get to; so you can use filters for password checking, user logging, even restricting access to Web resources based on the time of day.

The MVC architecture is designed to be used as your Web applications become larger and larger. This architecture provides a way of dividing up your application into distinct parts, following the divide-and-conquer strategy. By separating your Web application into well-defined parts, you can make it easier to maintain and debug.

Restricting Access with Filters

Filters give you control both before and after a user accesses a Web resource on Java-enabled servers. Usually, you get a direct connection between the browser and a Web resource such as an HTML page, Java servlet, or JSP page:

 --------------          --------------
|              |        |   Web        |
|              |------->|   resource   |
|    browser   |        |   (HTML page,|
|              |<-------|   servlet,   |
|              |        |   JSP, etc.) |
 --------------          --------------

However, filters you install get control before and after the Web ...

Get Ajax Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.