Declaration

It doesn't make much sense using a Java helper class just to manage an integer, we can easily declare the integer we need as instance variable for the JSP page itself. To do that we use the JSP declaration element (<%! %>).

Actually, in a declaration element we could put instance variables, member functions and even inner classes. Using this feature, we could significatively shrink our code to this couple of lines:
<%! private int count; %>
The page count is now: <%= ++count %>
I wrote the first draft of this post while reading of the seventh chapter of Head First Servlet and JSP.

No comments:

Post a Comment