Power to Build

Home » Misc » JSP Commenting Styles

JSP Commenting Styles

There are several ways to comment in a JSP file. When you are inside Java code (those scriptlets, inside <% %>), you can use Java commenting style. // for single line comment and /* */ for block comments. It’s the comments you add outside the Java block (inside HTML) that this tip is concerned about.

Below is the HTML style comment:
<!– This is a HTML comment –>

Now this comment is part of the HTML syntax and thus will end up in the generated HTML source sent to browser. So, if you have a lot of these, these could increase the size of the HTML file(s) generated and sent to client. If the user does Right click in browser she can view comments in the source!

The other style meant for JSP, is a slight variation of the above:
<%– This is a hidden comment in JSP –%>

This is a hidden comment in the sense, it doesn’t reach browser. Use this wherever you currently comment using HTML syntax, so the readability of HTML won’t be affected much, without increasing the size of generated HTML response (files).

See here for a nice example.

For an example of commenting style(s) in E-filing code, below are some comments from F-renewal-submit-confirm.jsp

Java Comments

        //PR2095 [start]
        ldbl_interest           = (SQL.getBigDecimal(webbr.web_calculate_interest(ls_fcc[li_row], IDL.getDate((java.sql.Date)ldt_fcc_effdate_util),
                                    IDL.getDate((java.sql.Date)ldt_due_date_util), ls_int_rate_name,
        ldbl_penalty            = (SQL.getBigDecimal(webbr.web_calculate_penalty(ls_fcc[li_row], IDL.getDate((java.sql.Date)ldt_fcc_effdate_util),
                                    IDL.getDate((java.sql.Date)ldt_due_date_util), ls_pen_rate_name,
        //PR2095 [end]


These we could leave as is. JSP/Java compilers will ignore these comments while generating Servlet classes.

HTML Comments (Could use JSP comment here)

        <table border = “0” cellspacing=”0″ width=”100%” style=”border-collapse: collapse” bordercolor=”#111111″ cellpadding=”10″><tr>
          <td height=”50″ align=”center” width=”100%” bgcolor=”#FFFFCC”>
          <!– CR8xx (beg) – remove confirmation verbiage for mail in check process –>
          <% if (ls_tender_type.compareTo(“CHE”) != 0) { %>
          <!– CR8xx (end) –>


The lines in bold are the HTML comments. As mentioned above, these are “visible” comments and also increase the size of the HTML response sent to browser.  These could be changed to JSP style hidden comments, so they won’t reach browser. If you have too many HTML comments, you are sending extra bytes unnecessarily to the browser. And, in some cases, you may be giving out too much internal information too. So, cleanup those HTML comments in your JSP files.

Note: This is a very old JSP application running inside EAServer. I know, JSP design has changed over the years. We are just maintaining and enhancing existing code. Please bear with the mention of scriptlets here.


Comments, please?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: