JavaMix

it`s all about JavaPrograming

Archive for the ‘tips’ Category

output comment and hiddencomment in JSP

output comment:

A comment that is sent to the client in the viewable page source.The JSP engine handles an output comment as uninterpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.
JavaMix Blog
JSP Syntax
<!– comment [ <%= expression %> ] –>

Example 1

<!– This is a commnet sent to client on
<%= (new java.util.Date()).toLocaleString() %>
–>

Displays in the page source:
<!– This is a commnet sent to client on March 28, 2009 –>


hiddencomment

A comments that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or “comment out” part of your JSP page.

You can use any characters in the body of the comment except the closing –%> combination. If you need to use –%> in your comment, you can escape it by typing –%\>.
JSP Syntax
<%– comment –%>

Example:
<%–
Document   : commenttest
Created on : Mar 28, 2009, 11:48:27 AM
Author     : vijay
–%>

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd”&gt;

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>JSP Page</title>
</head>
<body>

<!– this is visible comment–>                          comment 1
<%– this comment is not visible  –%>          comment 2
<h1>Hello World!</h1>
</body>
</html>


output:

when you go for browser source code it will  displays the following :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <!-- this is visible comment-->       comment 1 only displays

        <h1>Hello World!</h1>
    </body>
</html>


Written by katta vijay

March 28, 2009 at 6:41 am

Posted in j2ee, Jsp, tips

Tagged with , , , ,