Saturday, June 21, 2008

JSP Comment vs HTML Comment - what's the difference?

JSP Comment vs HTML Comment - what's the difference?

JSP Comment

<%-- comment text --%> - this is the format of the JSP comments specified in the JSP Specifications. A JSP Comment is removed by the JSP Engine at the translation time itself and the compilation unit doesn't contain them. The comment processing in JSP is very similar to what we have in any other language. Comments don't need to ne compiled as we all know that they are not executed and they simply serve the purpose of making the source code more readable, and maintainable.

HTML Comment

<!-- comment text --> - this is the syntax of an HTML comment as specified by the HTML Specifications. A JSP page considers this as a normal HTML tag and hence it doesn't remove them. All HTML comments are maintained in the response and one can easily see them jusy by viewing the page source of the rendered HTML page in the browser.

Difference between JSP Comment & HTML Comment

JSP Comments are removed by the JSP Engine during the translation phase (JSP Comments are not even part of the compilation unit) whereas the HTML Comments are treated like any other HTML tage and hence they are maintained throughout. This is reason why we can easily see the HTML comments in the browse by viewing the source of the page.

What about // or /*...*/? Are they JSP Comments?

No... they are only Java comments. Since, we are allowed to embed Java code into a JSP page, hence we can have them in a valid JSP page. These comments are treated the same way they are treated in a normal Java program. They all are removed before compilation and like JSP Comments they are also not part of the compilation unit.



MagicDude4Eva said...

Are there any tools available to bulk-remove HTML-comments from JSPs?

Geek said...

magicdude4eva: I don't know any such popular tool which can bulk remove HTML-comments from JSPs. You may probably need to write a custom parser, which I suppose won't be that difficult.

There is one tool called 'JSP2X' which converts JSP pages into JSP documents (JSPX). This tool converts HTML comments into their XML counterparts. Please find details of this tool at the below link:-

Hope this helps. Thanks for visiting/posting!

formaldresses4us said...

I was actually looking for this resource a few weeks back. Thanks for sharing with us your wisdom.This will absolutely going to help me in my projects .

Flower Girl Dresses|Empire Wedding Dresses|New Style Wedding Dresses

cheap nike shox said...

Your blog post were very good

Vicky Ram said...

Great Post. Keep sharing such kind of worthy information

JAVA Training in Chennai

JAVA Course in Chennai