Until now I found only one place I can use it. It's an admin page where I am monitoring our server's current memory usage and memory usage "delta" between two "events". There you need some kind of "local", "static" (in C++ terms) variables to keep track of previous/current memory usage and I found <%! %> a good shortcut for doing it.
I think it's enough for a programmer to look into the servlet code generated by a jsp compiler to really understand what the JSP spec means by "Declaration". For a webdesigner, it's hard to avoid the confusion, so you 're right, they shouldn't use <%! %> at all. What would you prefer to call this "declaration" instead? "JSP Class Member definition"? david -----Original Message----- From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of Geert Van Damme Sent: Wednesday, January 09, 2002 7:48 AM To: [EMAIL PROTECTED] Subject: Re: I want to make code shorter. > lol.. u sound like u have had a bad experience with declaration blocks :) Absolutely. I've seen too many people use <%! %> tags to declare variables e.g. It was absolutely a stupid move of the people who wrote the JSP specs to call <%! %> a 'declaration'. I know what they mean and in some way they are correct, but it is easil misunderstood. e.g. I read an article in java developers journal (which is supposed to be one of the biggest about Java isn't it?) about JSP-JDBC. For 1 it's a bad thing to do your JDBC code inside a JSP itself, but ok, I can live with that. The trouble was that in this article he used code like: <%! Connection conn = null; Statement stmt =null; ResultSet rs = null; %> bla bla <% conn = getConnection ... and all JDBC stuff %> Now listen everybody: DON'T EVER DO THIS !!!!!!!!!! Don't declare variables in a 'declaration' (I know, there are exceptions, but for now, simply DON'T ;-)! ..... > Everyone should know what the difference between > scriplets/declarations/and > expressions is. > If your not a newbie and you dont know exactly what a declaration block is > then you shouldnt be coding JSP pages. > (sorry if that sounded rude. it's early and i cant think of a more tactful > way to say that) No, you're wrong ;-) No matter what you say, JSP will always be used by newbies (now I think about it, every technology, especially new technology, will always be used by newbies, won't it?). It's much more important that newbies get clear and correct information like (sorry if I repeat this quite often ;-), I think it's necessary) DON'T USE DECLARATIONS AT ALL !!!!! It's only natural that JSP will be used by the more intelligent webdesigner. people that knwo the basics about making dynamic pages, they know what if() for and while() is about, but don't completely get OOP or the servlet model. Geert Van Damme =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com
