Chapter 16. Developing JSP Custom Actions
Custom actions let you encapsulate logic and make it available to page authors in a familiar format. Throughout this book, a number of generic custom actions are used for such tasks as accessing a database, including localized content, encoding URLs, and much more. Using these actions, the amount of Java code in the JSP pages can be kept to a minimum, making the application easier to debug and maintain. However, for a complex application, the generic actions presented in this book are not enough. Perhaps you want to develop application-specific actions to access the database instead of putting SQL statements in the JSP pages. Or you may want to present complex data as a set of nested HTML tables with cells formatted differently depending on their values. Instead of using conditional scripting code in the JSP page to generate this table, an application-specific custom action can be used.
Custom actions know about their environment. They automatically get access to all information about the request, the response, and all the variables in the JSP scopes. Another common use for a custom action is as an HTTP-specific adapter to a bean. JavaBeans components are frequently used in a JSP application, and a bean is easier to reuse if it doesn’t know about the environment where it’s used.
To develop a custom action, you use a set of classes and interfaces referred to in the JSP 1.1 specification as the tag extension mechanism. The simplest custom ...