Comments in Jsp

Here we have discussed the use of comments in JSP page and how they are displayed.

Comments in Jsp

JSP comments are very similar to HTML. They are not displayed in the Output of the program when it is executed. They do not affect the size of the file. JSP page are used to understand the program in a much better way.

Two types of comments are allowed in a JSP page:

Hidden comment

Such comments written under <%-- Hidden comment --%> and does not appear in the output.

Output comment:

Such comments written under <!-- Output comment> and appears in the output.

// is used to pass the comment inside the directive.

Example:

<HEAD>
<TITLE> </TITLE>
</HEAD>
<BODY>
<font size="6" color ="#000080">JSP Comments</font><br> 

<% 
// System.out.println
("This is Single line comment inside scriptlet tags");
/*
System.out.println
("This is multiline comment inside scriptlet tags");
System.out.println
("This is multiline comment inside scriptlet tags");
System.out.println
("This is multiline comment inside scriptlet tags");

*/
%> 
<%-- 
<% 
if (Math.random() > .5) {
out.println("<b>You win!</b>");
} else {
out.println("Sorry, you lose. Try again.");
} 
%>
<%=userName %>

--%>
<!--
this is HTML tag
-->
<table>
<tr>
<td>
<b>Single line comment inside scriptlet tags:</b> </br>

// System.out.println("Roseindia.net");</br>
<b> Multiline comment inside scriptlet tags:</b></br>
/*</br>
System.out.println("Roseindia.net");</br>
System.out.println("Roseindia.net");</br>
System.out.println("Roseindia.net");</br>

*/</br>
<b>JSP Comment:</b> System.out.println
("Roseindia.net");<br>

<br>

</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</BODY>
</HTML>

Resource: