The reason you cant do this is because any scriptlets you write in a JSP page are placed in the service method of the servlet the container creates from your JSP page. In Java, you can't have a method within a method. You can have a class within a method, but not a method by itself.
Declarations, on the other hand, are compiled into members (variables, methods) of the generated servlet. So, you can write methods there.
The bottom line is this ... listen to Mr. Dittmer .. dont do it!! Write you java code in classes, custom tags or servlets. Whoever has to maintenance your code later ... and that might be you ... will thank you for it!
SCJP 5.0 (preparing for SCWCD)
posted 8 years ago
Thanks keith for the detailed and thoughtful reply. It helped me understand lot other things too....