jsp comments ,java comment, Html comment


Comments

Inside jsp we can use three types of comments.
1.    Jsp comments
2.    Html/xml comments
3.    Java comments
                                               1.     Jsp Comments:
     Syntax :

<%--    comment     --%>

Description :

1.    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’.
2.    Also known as hidden comments because there are not visible in the remaining phages of jsp life cycle because jsp comments data ignored by java compiler at compilation time.
3.    It is highly recommended to use jsp comments

Example :

<%@ page import="java.util.*" %>
<%
          String s = "myjavahub";
          out.println("<h2>"+s);
%>
<%-- This JSP comment part will not be included in the response object --%>
: : : <%= new Date()%>

Output:


                                     2.     HTML/XML Comment:
Syntax:

< ! - -   XML/HTML Comment   - - >

Description:

1.    The JSP container treats this HTML comment tag as equal as any other HTML tags.
2.    When  ever  we got the  response right click on browser window and click on view page source, the content given between this html/xm  comment tag is visible.
3.    This is not anyway related to the JSP container, it is the expected behaviour of this HTML tag and Hence these are not recommended to use. 
                                     
                                               3.     Java Comments:
Syntax:
 1.    // single line comment
2.       /*     multi line crmment        */

Description:

1.    These are also known as scripting comments.
2.    These are visible in the generated servlet source code.  And not visible in the      remaining phases.
 Example:

<%
          String s = "myjavahub";
          //printing string value 
          out.println("<h2>"+s+"</h2>");
          /*  jsp implicit objects are not available for declarative tag */
 %>

 Output: http://localhost:8080/Scwcd_jsp/test.jsp
myjavahub

Note:Among expression, declaration, scriptlet and Jsp comments we can’t use one inside another i.e.  Nesting of the scripting elements is not allowed otherwise we will get compile time error with 500 status code.

Example: test.jsp

<%
        Out. Println(<%= 2*3 %>);
 %>
  <%!
      Public void m1 ( )
      {
            <%
                  out.println("Hello");
            %>
       }
   %>
 <%!
      <%-- This method is very useful --%>
       public void m1 ( )
       {
               System.out.println("Hello");
       }
  %>
<%!
        public void m1( )
         {
            System.out.println(<%= new Date( ) %>)
         }
  %>

Output:




Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

2 comments:

  1. Nice post mate, keep up the great work, just shared this with my friendz
    澳洲IT代写

    ReplyDelete
  2. This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff.
    cs代写

    ReplyDelete