You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2001/10/22 19:11:24 UTC

DO NOT REPLY [Bug 4339] - Cannot use "//" comments in JSP code

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339

Cannot use "//" comments in JSP code

craig.mcclanahan@sun.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX



------- Additional Comments From craig.mcclanahan@sun.com  2001-10-22 10:11 -------
You should not be using "//" comments.  You have absolutely no control over the
Java code that is generated for your page, so it is your responsibility to use
well-formed constructs.  In this particular case, that means to use /* */ style
comment markers so that you can explicitly close them.  Even if we changed
Tomcat to do what you suggest, depending on this would not be portable and you'd
have massive problems as soon as you tried to switch to some other container
that didn't do it.

Using scriptlets at all can lead you into lots of other problems (such as
intermixing business logic and presentation logic that makes it very hard to
maintain and enhance your applications), but that is a whole separate
discussion.

Re: DO NOT REPLY [Bug 4339] - Cannot use "//" comments in JSP code

Posted by Paul Speed <ps...@progeeks.com>.
Ah,

Sorry.  _That_ makes perfect sense.

It's what I get for not reading the original bug report in more 
detail.

Although, I would expect in the following case...

> When you do something like this:
> 
>   <% System.out.println(); // Hello %> Some template text
> 
> then this gets translated into
> 
>   System.out.println();  // Hello Some template text

To instead get:

System.out.println(); // Hello 
out.print( "Some template text" );

Since "Some template text" is clearly outside of the <% %>, wouldln't
it be turned into generated output instead of code?  Or am I being
pedantic and what you really meant was:

System.out.println(); // Hello out.print( "Some template text" );

or somesuch?

-Paul Speed

"Craig R. McClanahan" wrote:
> 
> On Mon, 22 Oct 2001, Paul Speed wrote:
> 
> > Date: Mon, 22 Oct 2001 13:48:08 -0400
> > From: Paul Speed <ps...@progeeks.com>
> > Reply-To: tomcat-dev@jakarta.apache.org
> > To: tomcat-dev@jakarta.apache.org
> > Subject: Re: DO NOT REPLY [Bug 4339]  - Cannot use "//" comments in JSP
> >     code
> >
> > Only partially related to the bug, so I'm replying directly instead
> > of through bugzilla...
> >
> > Does this mean that JSP uses a different Java language specification?
> > If so, where can I find this separate specification?  Are there any
> > other big things like this that are incompatible with normal Java
> > syntax?
> >
> 
> The JSP specification does not mandate the use of Java as a scripting
> language -- you can use any language you want (as specified by the
> "language" attribute of the <%@ page %> directive).  However, many of the
> features related to scripting are defined *only* for Java.
> 
> Note also that Jasper (the JSP page compiler in Tomcat) only supports Java
> as a scripting language at the moment.
> 
> However, more germane to this bug report:
> 
> * Scriptlets are required to be well-formed according to the
>   rules of the scripting language in use (JSP 1.2, Section 2.11.2).
>   Thus, if you mistakenly leave off a semicolon at the end of a
>   Java statement in a scriptlet, the compilation error you get is
>   your fault.  It's also your fault if the scope of your language
>   element extends outside the closing "%>" delimiter in a manner
>   that causes invalid code to be created (such as mismatching "}"
>   brackets), or the case described in the following point.
> 
> * Scriptlets are translated into the generated code according
>   to the following rule (JSP 1.2, Section 6.4.2):
> 
>     <% scriptlet %>     -->        scriptlet
> 
>   In other words, no newline is added after the "%>" by the page
>   compiler (though the developer could certainly put a newline there).
> 
> When you do something like this:
> 
>   <% System.out.println(); // Hello %> Some template text
> 
> then this gets translated into
> 
>   System.out.println();  // Hello Some template text
> 
> and you get what you pay for.  If you want to use // comments, do this
> instead:
> 
>   <% System.out.println(); // Hello
>   %> Some template text
> 
> and it will work fine.
> 
> > Thanks,
> > -Paul Speed
> >
> 
> Craig
> 
> > bugzilla@apache.org wrote:
> > >
> > > DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
> > > RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
> > > <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339>.
> > > ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
> > > INSERTED IN THE BUG DATABASE.
> > >
> > > http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339
> > >
> > > Cannot use "//" comments in JSP code
> > >
> > > craig.mcclanahan@sun.com changed:
> > >
> > >            What    |Removed                     |Added
> > > ----------------------------------------------------------------------------
> > >              Status|NEW                         |RESOLVED
> > >          Resolution|                            |WONTFIX
> > >
> > > ------- Additional Comments From craig.mcclanahan@sun.com  2001-10-22 10:11 -------
> > > You should not be using "//" comments.  You have absolutely no control over the
> > > Java code that is generated for your page, so it is your responsibility to use
> > > well-formed constructs.  In this particular case, that means to use /* */ style
> > > comment markers so that you can explicitly close them.  Even if we changed
> > > Tomcat to do what you suggest, depending on this would not be portable and you'd
> > > have massive problems as soon as you tried to switch to some other container
> > > that didn't do it.
> > >
> > > Using scriptlets at all can lead you into lots of other problems (such as
> > > intermixing business logic and presentation logic that makes it very hard to
> > > maintain and enhance your applications), but that is a whole separate
> > > discussion.
> >

Re: DO NOT REPLY [Bug 4339] - Cannot use "//" comments in JSP code

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 22 Oct 2001, Paul Speed wrote:

> Date: Mon, 22 Oct 2001 13:48:08 -0400
> From: Paul Speed <ps...@progeeks.com>
> Reply-To: tomcat-dev@jakarta.apache.org
> To: tomcat-dev@jakarta.apache.org
> Subject: Re: DO NOT REPLY [Bug 4339]  - Cannot use "//" comments in JSP
>     code
>
> Only partially related to the bug, so I'm replying directly instead
> of through bugzilla...
>
> Does this mean that JSP uses a different Java language specification?
> If so, where can I find this separate specification?  Are there any
> other big things like this that are incompatible with normal Java
> syntax?
>

The JSP specification does not mandate the use of Java as a scripting
language -- you can use any language you want (as specified by the
"language" attribute of the <%@ page %> directive).  However, many of the
features related to scripting are defined *only* for Java.

Note also that Jasper (the JSP page compiler in Tomcat) only supports Java
as a scripting language at the moment.

However, more germane to this bug report:

* Scriptlets are required to be well-formed according to the
  rules of the scripting language in use (JSP 1.2, Section 2.11.2).
  Thus, if you mistakenly leave off a semicolon at the end of a
  Java statement in a scriptlet, the compilation error you get is
  your fault.  It's also your fault if the scope of your language
  element extends outside the closing "%>" delimiter in a manner
  that causes invalid code to be created (such as mismatching "}"
  brackets), or the case described in the following point.

* Scriptlets are translated into the generated code according
  to the following rule (JSP 1.2, Section 6.4.2):

    <% scriptlet %>     -->        scriptlet

  In other words, no newline is added after the "%>" by the page
  compiler (though the developer could certainly put a newline there).

When you do something like this:

  <% System.out.println(); // Hello %> Some template text

then this gets translated into

  System.out.println();  // Hello Some template text

and you get what you pay for.  If you want to use // comments, do this
instead:

  <% System.out.println(); // Hello
  %> Some template text

and it will work fine.

> Thanks,
> -Paul Speed
>

Craig


> bugzilla@apache.org wrote:
> >
> > DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
> > RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
> > <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339>.
> > ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
> > INSERTED IN THE BUG DATABASE.
> >
> > http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339
> >
> > Cannot use "//" comments in JSP code
> >
> > craig.mcclanahan@sun.com changed:
> >
> >            What    |Removed                     |Added
> > ----------------------------------------------------------------------------
> >              Status|NEW                         |RESOLVED
> >          Resolution|                            |WONTFIX
> >
> > ------- Additional Comments From craig.mcclanahan@sun.com  2001-10-22 10:11 -------
> > You should not be using "//" comments.  You have absolutely no control over the
> > Java code that is generated for your page, so it is your responsibility to use
> > well-formed constructs.  In this particular case, that means to use /* */ style
> > comment markers so that you can explicitly close them.  Even if we changed
> > Tomcat to do what you suggest, depending on this would not be portable and you'd
> > have massive problems as soon as you tried to switch to some other container
> > that didn't do it.
> >
> > Using scriptlets at all can lead you into lots of other problems (such as
> > intermixing business logic and presentation logic that makes it very hard to
> > maintain and enhance your applications), but that is a whole separate
> > discussion.
>


Re: Cannot use "//" comments in JSP code

Posted by Jon Stevens <jo...@latchkey.com>.
on 10/22/01 10:48 AM, "Paul Speed" <ps...@progeeks.com> wrote:

> Only partially related to the bug, so I'm replying directly instead
> of through bugzilla...
> 
> Does this mean that JSP uses a different Java language specification?
> If so, where can I find this separate specification?  Are there any
> other big things like this that are incompatible with normal Java
> syntax?
> 
> Thanks,
> -Paul Speed

This is yet another great reason why you shouldn't embed Java code within
your templates. JSP != Java

-jon


Re: DO NOT REPLY [Bug 4339] - Cannot use "//" comments in JSP code

Posted by Paul Speed <ps...@progeeks.com>.
Only partially related to the bug, so I'm replying directly instead
of through bugzilla...

Does this mean that JSP uses a different Java language specification?
If so, where can I find this separate specification?  Are there any
other big things like this that are incompatible with normal Java 
syntax?

Thanks,
-Paul Speed

bugzilla@apache.org wrote:
> 
> DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
> RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
> <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339>.
> ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
> INSERTED IN THE BUG DATABASE.
> 
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4339
> 
> Cannot use "//" comments in JSP code
> 
> craig.mcclanahan@sun.com changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|NEW                         |RESOLVED
>          Resolution|                            |WONTFIX
> 
> ------- Additional Comments From craig.mcclanahan@sun.com  2001-10-22 10:11 -------
> You should not be using "//" comments.  You have absolutely no control over the
> Java code that is generated for your page, so it is your responsibility to use
> well-formed constructs.  In this particular case, that means to use /* */ style
> comment markers so that you can explicitly close them.  Even if we changed
> Tomcat to do what you suggest, depending on this would not be portable and you'd
> have massive problems as soon as you tried to switch to some other container
> that didn't do it.
> 
> Using scriptlets at all can lead you into lots of other problems (such as
> intermixing business logic and presentation logic that makes it very hard to
> maintain and enhance your applications), but that is a whole separate
> discussion.

Cannot use "//" comments in JSP code - clarifications ?

Posted by Denis Balazuc <de...@trader.com>.
Hi all

I've read that bug report about comments in JSP files and don't really
understand - can someone clarify the issue for me ? thanks

I'm wondering what's wrong with "//", and what I might be doing wrong as I
myself use such comments within JSP files...
(those comments use to work well...it's even better than using HTML comments
in a JSP file as they won't appear in the generated HTML)

Actually, I don't understand the argument "You should not be using "//"
comments"

--"//" are part of the java language spec
-- the JSP API is made for implementing server-side pages using the java
language

Therefore, JSP pages should accept everything that it's in the Java specs,
including "//".
If such comments are misplaced and the compilation fails, Tomcat is not
supposed to do anything..

So what's the real issue then ?

> ------- Additional Comments From craig.mcclanahan@sun.com  2001-10-22
10:11 -------
> You should not be using "//" comments.  You have absolutely no control
over the
> Java code that is generated for your page, so it is your responsibility to
use
> well-formed constructs.  In this particular case, that means to use /* */
style
> comment markers so that you can explicitly close them.  Even if we changed
> Tomcat to do what you suggest, depending on this would not be portable and
you'd
> have massive problems as soon as you tried to switch to some other
container
> that didn't do it.
>
> Using scriptlets at all can lead you into lots of other problems (such as
> intermixing business logic and presentation logic that makes it very hard
to
> maintain and enhance your applications), but that is a whole separate
> discussion.