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?

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:

  class Herge {
	private String haddockSays="";
	public Herge() {
	    haddockSays="Billions of blistering Bashi-bazouks!";
	public String getHaddockSays() {
	   return haddockSays;

<% Herge captain = new Herge(); %> <h1> <%= captain.getHaddockSays() %> </h1> </body> </html>
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.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact