Sometimes you need to output a comment in the client-side HTML source and insert a JSP expression inside that comment. Note that HTML comments are sent to the browser, so users can see them when they choose "View Source"; JSP expressions, however, are evaluated on the server first, and the result is then written into the response.
JSP Syntax
<!-- comment [ <%= expression %> ] -->
Here, <%= expression %> is a JSP expression. As long as the expression itself is valid, it can be placed inside the comment content.
Example 1
Writing a normal HTML comment in a JSP page:
<!-- This file displays the user login screen -->
The HTML source code seen by the client is still:
<!-- This file displays the user login screen -->
Example 2
Inserting a JSP expression into an HTML comment:
<!-- This page was loaded on <%= (new java.util.Date()).toLocaleString() %> -->
The HTML source code seen by the client will become the evaluated content, for example:
<!-- This page was loaded on January 1, 2000 -->
The actual date and format depend on the server runtime environment, locale settings, and the expression's return value. In modern Java code, you should generally avoid continuing to use the deprecated Date#toLocaleString() method; use java.time or an explicit date-formatting approach instead.
Summary
This form is still essentially an HTML comment, so it will appear in the browser's "View Source" output. The difference is that the JSP expression is executed on the server first, and the result is then placed into the comment text.
In addition, // and / ... / are also common comment forms, but they belong to JavaScript or CSS syntax and do not work as HTML comments. HTML comments should use <!-- ... -->.
