How comment a JSP expression?

JspComments

Jsp Problem Overview


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

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

Jsp Solutions


Solution 1 - Jsp

Pure JSP comments look like this:

<%-- Comment --%>

So if you want to retain the "=".you could do something like:

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

The key thing is that <%= defines the beginning of an expression, in which you can't leave the body empty, but you could do something like this instead if the pure JSP comment doesn't appeal to you:

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

Code Conventions for the JavaServer Pages Technology Version 1.x Language has details about the different commenting options available to you (but has a complete lack of link targets, so I can't link you directly to the relevant section - boo!)

Solution 2 - Jsp

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.

Solution 3 - 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 -->

Solution 4 - Jsp

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.

Solution 5 - Jsp

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

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

Solution 6 - Jsp

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

Solution 7 - Jsp

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 %>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkmiloView Question on Stackoverflow
Solution 1 - JspJonny BuchananView Answer on Stackoverflow
Solution 2 - Jspkavi temreView Answer on Stackoverflow
Solution 3 - Jspuser3190254View Answer on Stackoverflow
Solution 4 - JspJflywheelView Answer on Stackoverflow
Solution 5 - JsplockView Answer on Stackoverflow
Solution 6 - JspMani KasiView Answer on Stackoverflow
Solution 7 - JspjimView Answer on Stackoverflow