There are a number of different ways to generate dynamic content from JSP, as illustrated in Figure 11-1. Each of these approaches has a legitimate place; the size and complexity of the project is the most important factor in deciding which approach is appropriate. However, be aware that people err on the side of placing too much code directly in the page much more often than they err on the opposite end of the spectrum. Although putting small amounts of Java code directly in JSP pages works fine for simple applications, using long and complicated blocks of Java code in JSP pages yields a result that is hard to maintain, hard to debug, hard to reuse, and hard to divide among different members of the development team. See Section 11.3 (Limiting the Amount of Java Code in JSP Pages) for details. Nevertheless, many pages are quite simple, and the first two approaches of Figure 11-1 (placing explicit Java code directly in the page) work quite well. This chapter discusses those approaches. Figure 11-1. Strategies for invoking dynamic code from JSP. Types of JSP Scripting ElementsJSP scripting elements let you insert Java code into the servlet that will be generated from the JSP page. There are three forms:
Each of these scripting elements is described in more detail in the following sections. ![]() |