Abbey Workshop

JSP: JSP Comments

Comments are a very simple concept in Java Server Page. To make a comment, simply enclose text in a <-- --> pair. Any text contained in these tags are commented out, and do not appear in the HTML page created by the JSP. For example:

<%-- This is a comment --%>

One of the better uses of comments is for troubleshooting. You can use JSP comments to hide specific pieces of code. You can then test the code without a particular block misssing.

In the example below, one piece of code that prints a message is commented out. Run the example from the link below. You will see that none of the comments appear in the HTML document.

jspComment.jsp

   1:<html>
   2:<head>
   3:<title>JSP Comments Example</title>
   4:</head>
   5:<body>
   6:<h2>JSP Comments Example</h2>
   7:<%-- Two expressions are listed below. Only one should print.  --%>
   8:<p>Ex1: This code will execute: <%= "Print this" %><br>
   9:<%-- 
  10:Ex2: This code is commented out: <%= "Print this" %><br>
  11:--%>
  12:</p>
  13:</body>
  14:</html>