aspose file tools*
The moose likes JSP and the fly likes Is this an error by Sun? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Is this an error by Sun?" Watch "Is this an error by Sun?" New topic
Author

Is this an error by Sun?

Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
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
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
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.

James.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
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...
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

IMO, this is a mistake. You can only declare methods in a Declaration <%! %>. Variables can be declared in Scriptlets and Declarations.
Junilu


Junilu - [How to Ask Questions] [How to Answer Questions]
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Sorry, my mistake.
Previously I was just distinguishing between HTML and Java code in JSPs.
But what you are saying doesn't sound correct (method within method).
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Thanks! C'mon people, Sun's statement is in
http://java.sun.com/products/jsp/pdf/syntaxref12.pdf

Page 10...
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this an error by Sun?
 
Similar Threads
the equivalent XML-based tags
where is JSP v2.0 Syntax Reference ?
Get your scwcd queries answered: Nice design
Help in understanding JSM syantax.
JSP Include