[ Team LiB ] Previous Section Next Section

17.3 Body Tags

Various uses of body tags can make a difference in performance.

17.3.1 Use Include Directive, Not Action

The include directive <%@ include file="somefile.html" %> is a compile-time action, so it doesn't affect runtime performance (it takes effect when the JSP is compiled into a servlet). The include action <jsp:include page="somefile.jsp" flush="true"/> is a runtime action, so it adds overhead and decreases performance. Use the include directive whenever possible.

17.3.2 Minimize Scope of useBean Action

The useBean action has a scope associated with the bean created by the action. The scope defines the lifetime of the bean. Minimize the scope to minimize the resources taken by the bean—e.g., <jsp:useBean id="mybean" scope="page" />. You will need to use a wider scope (request, session, or application) to use beans with pages that are included.

17.3.3 Minimize Custom Tags

Custom tags have a performance cost, but they are useful. Try to minimize custom tags to only those required. BodyTags are more costly to performance than simpler custom tags. Using BodyTags to iterate on the page section contents makes the page significantly slower. (On the other hand, Jim Elliott wanted me to point out that custom tags are so much better than the alternative of mixing presentation and logic that eliminating custom tags may not be worth the performance gain.)

17.3.4 Use Redirects Versus Forwards

Redirect s (using sendRedirect( )) are slower than forwards (<jsp:forward ...>) because the browser has to make a new request for the redirect. The forward is a simple call that is internal to the servlet, and a redirect tells the browser to make a new request to the redirected target page.

    Previous Section Next Section