Showing posts with label JSP Comment vs HTML Comment. Show all posts

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

7:46 AM
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

- 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.
Read On 1 comments

Followers