Is this correct (Sun doc.)? In Sun's Jsp Syntax Reference http://java.sun.com/products/jsp/pdf/syntaxref12.pdf page 10, it says that a SCRIPTLET can contain a METHOD declaration. That's like saying that you can have a method declared inside another method in regular Java. Someone tried it here (not me) and said it didn't work. Is this an error by Sun? [This message has been edited by Tony Alicea (edited December 18, 2001).]
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
I interpret this differently. I guess you just got to think about what happens when a JSP get compiled (into a servlet). Depending on how you code your scriptlet variables/statements, they either get turned into class level members or just local variables/statements inside the compiled servlet's service methods. eg. this code has a method declared within a scriptlet, I would expect the resulting servlet to have an additional method declared similarly.
Joined: Jan 30, 2000
Thanks James, but your example is an example of a DECLARATION <%! %>which is used to define, among other things, member methods of the corresponding JSP servlet class. I was asking about SCRIPTLETS <% %> and Sun's statement that you can also declare methods inside them which I think is incorrect. For review, there are JSP DECLARATIONS, SCRIPTLETS and EXPRESSIONS...
A simple method within a method that is produced in the corresponding servlet won't compile, at least on my Tomcat 4.01 I think the error comes from ambiguity over the term "Scripting Element" and "scriptlet". According to http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro7.html "scripting elements" can contain declarations, scriptlets and expressions. So syntaxref12.pdf is wrong. IMO. Adam
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.