[jsp] How comment a JSP expression?

How can I comment a JSP expression like: <%= map.size() %>

Is there something like <%= // map.size() %>?

This question is related to jsp comments

The answer is


your <%= //map.size() %> doesnt simply work because it should have been

<% //= map.size() %>

One of:

In html

<!-- map.size here because --> 
<%= map.size() %>

theoretically the following should work, but i never used it this way.

<%= map.size() // map.size here because %>

There are multiple way to comment in a JSP file.

1.  <%-- comment --%>

A JSP comment. Ignored by the JSP engine. Not visible in client machine (Browser source code).

2.  <!-- comment -->

An HTML comment. Ignored by the browser. It is visible in client machine (Browser source code) as a comment.

3. <% my code //my comment %>

Java Single line comment. Ignored by the Compiler. Not visible in client machine (Browser source code).

4.   <% my code /**
         my comment  **/  
       %>

Java Multi line comment. Ignored by the compiler. Not visible in client machine (Browser source code).

But one should use only comment type 1 and 2 because java documentation suggested. these two comment types (1 & 2) are designed for JSP.


your <%= //map.size() %> doesnt simply work because it should have been

<% //= map.size() %>

My Suggestion best way use comments in JSP page <%-- Comment --%> . Because It will not displayed (will not rendered in HTML pages) in client browsers.


There are multiple way to comment in a JSP file.

1.  <%-- comment --%>

A JSP comment. Ignored by the JSP engine. Not visible in client machine (Browser source code).

2.  <!-- comment -->

An HTML comment. Ignored by the browser. It is visible in client machine (Browser source code) as a comment.

3. <% my code //my comment %>

Java Single line comment. Ignored by the Compiler. Not visible in client machine (Browser source code).

4.   <% my code /**
         my comment  **/  
       %>

Java Multi line comment. Ignored by the compiler. Not visible in client machine (Browser source code).

But one should use only comment type 1 and 2 because java documentation suggested. these two comment types (1 & 2) are designed for JSP.


You can use this comment in jsp page

 <%--your comment --%>

Second way of comment declaration in jsp page you can use the comment of two typ in jsp code

 single line comment
 <% your code //your comment%>

multiple line comment 

<% your code 
/**
your another comment
**/

%>

And you can also comment on jsp page from html code for example:

<!-- your commment -->

One of:

In html

<!-- map.size here because --> 
<%= map.size() %>

theoretically the following should work, but i never used it this way.

<%= map.size() // map.size here because %>

You can use this comment in jsp page

 <%--your comment --%>

Second way of comment declaration in jsp page you can use the comment of two typ in jsp code

 single line comment
 <% your code //your comment%>

multiple line comment 

<% your code 
/**
your another comment
**/

%>

And you can also comment on jsp page from html code for example:

<!-- your commment -->

One of:

In html

<!-- map.size here because --> 
<%= map.size() %>

theoretically the following should work, but i never used it this way.

<%= map.size() // map.size here because %>

My Suggestion best way use comments in JSP page <%-- Comment --%> . Because It will not displayed (will not rendered in HTML pages) in client browsers.


When you don't want the user to see the comment use:

<%-- comment --%>

If you don't care / want the user to be able to view source and see the comment you can use:

<!-- comment -->

When in doubt use the JSP comment.


your <%= //map.size() %> doesnt simply work because it should have been

<% //= map.size() %>

When you don't want the user to see the comment use:

<%-- comment --%>

If you don't care / want the user to be able to view source and see the comment you can use:

<!-- comment -->

When in doubt use the JSP comment.