Can I create an inner class within my JSP file? If yes, can it be dynamically reloaded when changed like the rest of the JSP?
Created May 4, 2012
Govind Seshadri Yes, you can declare inner classes within your JSP pages using declarations. The inner classes are also dynamically reloaded by your servlet engine's classloader if they change.
Consider the following example:
<html> <body> <%! class Herge { private String haddockSays=""; public Herge() { haddockSays="Billions of blistering Bashi-bazouks!"; } public String getHaddockSays() { return haddockSays; } } %>After the page has been compiled, if you decide to have Cap'n Haddock swear something else, the inner class Herge will be reloaded, and the JSP page will be recompiled.<% Herge captain = new Herge(); %> <h1> <%= captain.getHaddockSays() %> </h1> </body> </html>