Forums Register Login

methods within scriptlets

+Pie Number of slices to send: Send
The JSP V 1.2 syntax reference doc has the following sentence:

A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.
Can a scriptlet contain a method ?
+Pie Number of slices to send: Send
Here's what the JSP 1.2 spec says:


JSP.2.11.2
Scriptlets can contain any code fragments that are valid for the scripting language specified in the language directive. Whether the code fragment is legal depends on the details of the scripting language (see Chapter JSP.6).
...
When all scriptlet fragments in a given translation unit are combined in order they appear in the JSP page, they must yield a valid statement, or sequence of statements in the specified scripting language.


So... its sorta tricky how they word it -- a scriptlet can contain a method if its legal in the scripting language for it to containa method. As of right now Java is the only scripting language.... and as of right now -- its not legal.
That's because all of your scriplets are converted at request time into fragments of the _jspService(request,response) method. And in Java it's illegal to have a method defined within another method -- but it IS legal to define an anonymous class or local class.
Also, you can define a method in a <%! declaration statment%> that way it will be put outside the _jspService method.
+Pie Number of slices to send: Send
hi,
depending on why u need to use a method in the jsp page, there are many ways of going about.
U can even write a custom tag and put ur method in it.
U should check this link out....
http://java.sun.com/products/jsp/tags/11/syntaxref11.fm3.html
regards
syd
+Pie Number of slices to send: Send
hi again,
just thought i'd give u another pointer...
http://developer.netscape.com/viewsource/kuslich_jsp/kuslich_jsp.html
hope this helps..it even has an example
regards
syd
Goodbye moon men. Hello tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1620 times.
Similar Threads
sybex (again) question
scriptlet
Help on Tags
Need clarification on Ch. 10 mock question 17.
can we use EL inside scriptlets
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:02:52.