There are three main ways to put comments into JSP files: HTML comments, JSP “hidden comments” and Java comments.
HTML comments (reference)
<!- – This is an HTML comment – ->
The JSP engine will place HTML comments in the data stream sent to the user’s browser. This makes them useful for debugging, but they do take up bandwidth and are visible to users who select View/Source in their browser.
JSP hidden comments (reference)
<- – This is a JSP hidden comment – ->
Update: I had written the wrong syntax for JSP hidden comments. The above syntax is correct.
The JSP engine does not process the contents of hidden comments. They are useful for documenting as well as commenting-out sections of the JSP.
Java comments
<% /* This is a Java comment */ %>
Using both Java comments and JSP hidden comments requires some care. Java comments can be placed inside hidden comments, but hidden comments cannot be placed inside Java comments, because the ”>” part of the closing ”- ->” would terminate the Java block. 1
In my JSPs I default to using hidden comments, unless there is a good reason to use one of the other two. A simple hidden comment is almost always the best choice.
Sun’s Code Conventions for the JavaServer Pages Technology Version 1.x Language has more to say on this topic.
1 Your mileage may vary. While using WebSphere Application Server v4, I once mis-typed the end of a JSP hidden comment as ”- >” instead of ” -%>”. WebSphere placed the entire JSP starting from the end of the comment onto the outgoing data stream without processing it, and the browser ended up receiving the JSP tags. It took a good hour to figure out what was happening, and why.
Installed another Gentoo Linux box at home this week. The box is only a 233MHz PII so the install was quite slow.
I am very pleased with the result, and will be using it as a firewall and Samba server.