JSP Comments

There is only one type of JSP comment available by JSP specification.

JSP Comment Syntax:
<%-- comment --%>

This JSP comment tag tells the JSP container to ignore the comment part from compilation. That is, the commented part of source code is not considered for the content parsed for ‘response’.

Example:
<%-- This JSP comment part will not be included in the response object --%>

Is this a JSP Comment?

<!-- comment --> is not a JSP comment. This is HTML comment. The JSP container treats this HTML comment tag as equal as any other HTML tags. When view source is done, the content given between this tag is visible. This is not anyway related to the JSP container, it is the expected behaviour of this HTML tag.

Example

<!-- This HTML comment part is included in the response object and can be seen in view source -->

// or /* comment */ used inside the <% %> scriplet tag is also not a JSP comment. This is just a java comment and JSP container doesn’t reserve any special treatment for this comments usage.

Therefore, there is nothing called as hidden comment or output comment in JSP by specification.

This JSP tutorial was added on 13/05/2008.

Comments on "JSP Comments" Tutorial:

  1. SenthilKumar says:

    Hi. your site is good.

    I have a question. Which is better to use.

    JSP Comment
    HTML Comment
    JAVA Comment

  2. Joe says:

    @Senthilkumar,
    JSP Comments or Java Comments or HTML Comments? It depends on the part of code you want to comment, since JSP comments can be used to comment out, HTML or scriplets also.

  3. ilanthamilan says:

    hai,this is useful for easily understanding the jsp

  4. chinna says:

    it will depends on ur requirement
    Jsp comment is best to use

  5. dev says:

    can i know how many types of jsp comments

  6. tuhin says:

    joe, thanks… you are excellent buddy…

  7. sukanya nath says:

    can you please tell me the jsp or html codes for posting comments in a website?

  8. Aishwarya Prakash Pandey says:

    I think it is better to use jsp comment in comparison to others ..

    Aishwarya Prakash Pandey

  9. Paul says:

    is not a JSP comment.”

    This is not true. It is a JSP “HTML Comment” and can contain an expression that is evaluated when the page is loaded.

    referred to here as a JSP Comment is actually a JSP “Hidden Comment” and is NOT sent to the browser.

  10. Paul says:

    is not a JSP comment.”

    This is not true. It is a JSP “HTML Comment” and can contain an expression that is evaluated when the page is loaded.

    referred to here as a JSP Comment is actually a JSP “Hidden Comment” and is NOT sent to the browser.

  11. sameena says:

    in this u said that it can be seen in view seen… Can u pls Explain it….

  12. sameena says:

    for html comment u said that it can be seen in view code… Can u pls Explain it….

  13. Raja Balu says:

    Excellent Man…. I have 7+ IT exp… I was not aware of such thing.

  14. Ritanshu Goel says:

    hello sir i want to know how to send sms through jsp code to a mobile.Plese help me.
    Waiting for your response.
    Thank you

  15. Amitabha Roy says:

    “Therefore, there is nothing called as hidden comment or output comment in JSP by specification.” —– I’ve really liked it. Its a very good observation.

  16. Amitabha Roy says:

    Hi Joe,

    This post can be made more funny (nay confusing for the beginners) if it includes:

    1. CSS comments: CSS may be a part of JSP file
    /* It is a CSS comment*/

    2. Javascript comments: Javascript may be a part of JSP file
    // Single line comment
    /* multiline
    comment */

    3.

    4. Hide script from old browsers:

    And so on. If HTML comment is considered as another type of JSP comment then why not the above types?

    Thanks,
    Amitabha

  17. vicky says:

    its depend upon your use…if you want to see the commented portion in your html source then you can use html comments else if you want to comment something inside your jsp code then only you can give jsp comment.

  18. mateen says:

    clearly explained :) thumbs upp!!

  19. Anonys says:

    can anyone tell me , what is the syntax for error message

Comments are closed for this "JSP Comments" tutorial.