• Post Reply Bookmark Topic Watch Topic
  • New Topic

methods within scriptlets

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naveen Sydney
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Naveen Sydney
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!