How to write a comment in a JSP page?

JSP comment marks to text or statements that the JSP container should ignore. A JSP comment is useful when you want to hide or "comment out", a part of your JSP page.

Following is the syntax of the JSP comments −

<%-- This is JSP comment --%>

Following example shows the JSP Comments −

      <title>A Comment Test</title>
      <h2>A Test of Comments</h2>
      <%-- This comment will not be visible in the page source --%>

The above code will generate the following result −

A Test of Comments

There are a small number of special constructs you can use in various cases to insert comments or characters that would otherwise be treated specially. Here's a summary −

S.No.Syntax & Purpose
1<%-- comment --%>
A JSP comment. Ignored by the JSP engine.
2<!-- comment -->
An HTML comment. Ignored by the browser.
Represents static <% literal.
Represents static %> literal.
A single quote in an attribute that uses single quotes.
A double quote in an attribute that uses double quotes.

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started