This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Take a look at the Java source code generated to see the difference. <%! %> declares an instance variable or member method <% %> creates a code fragment inside the service method of the JSP - for example, a local variable. Bill
<%! %> declares an instance variable or member method Think twice before you use this - it instantly makes a JSP thread-unsafe. You would be forced to either handle the threading issues yourself, or to decrease the scalability of your application by marking the page as thread-unsafe. - Peter
Peter den Haan
Joined: Apr 20, 2000
Think twice before you use it to declare a member variable (rather than a method), I mean. (Sorry, can't edit the post for some reason). - Peter
Anything within <%! ... %> will end up in the generated Servlet's class body, not in the body of the request handler method. If you define variable within this block you must ensure access from the request handler is either limited to read-only, or synchronized in order to make then thread-safe.
Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.