tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Qiao Jin" <>
Subject RE: Inner class trouble in JSP
Date Wed, 28 Jan 2009 02:54:21 GMT
Thanks. You are right. I figured this out after the refreshing myself on nested classes. My
mistake was using 'static' for the variable declaration. -Qiao

-----Original Message-----
From: Christopher Schultz [] 
Sent: Tuesday, January 27, 2009 6:17 PM
To: Tomcat Users List
Subject: Re: Inner class trouble in JSP

Hash: SHA1


Qiao Jin wrote:
> Here is an example, a menu header JSP included in various pages:
> <%!
> 	class MenuItem {
> 		String pageURL;
> 		String text;
> 		MenuItem(String url, String t) {
> 			this.pageURL = url;
> 			this.text = t;
> 		}
> 	}
> 	static MenuItem[] menu = new MenuItem[] {
> 		new MenuItem("page1.jsp", "Home"),
> 		new MenuItem("page2.jsp", "Info"),
> 		new MenuItem("page3.jsp", "Contact")
> 	};
> %>

Since you have static members (MenuItem[] menu), you must use a static
inner class (MenuItem). Just change your declaration of the MenuItem
class to be static.

'menu' is static in the test_jsp class, which means that it is
initialized at class load-time (before any instances of the class have
been created). MenuItem is not accessible until after an instance of
test_jsp has been created, so you have a paradox. The solution is to
make them both static. Or make them both non-static. Whichever you prefer.

- -chris

Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message