Header Ads

  • Breaking Now

    Explain different constituents of JSP like comments,expressions,declarations,scriptlets.

    JSP Comments:
    The JSP supports two type of comments :-
    -Output
    -Hidden
    JSP Output Comments are those ones which can be viewed on the HTML file, while Hidden Comments are never shown.

    JSP Expressions:
    The JSP expression tag is inserts Java values directly into the output. The syntax of the Expression tag is:
    <%= expression %>

    This kind of tag contains is evaluated, converted to a String, and inserted where the expression appears in the JSP file.

    JSP Declarations:
    JSP declarations are used to declare variables.To add a declaration, the <%! and %> sequences is used to enclose declarations,and ends in semi-colon. These variables can be used within functions and expressions.It is not a good practice to declare variables in global space as such variable are shared by multiple threads and which may change it's values in an inconsistent manner.To avoid such a scenario one must make these variables as synchronized but then it hampers the performance of the JSP .Usually variables are declared within local scope of Java scriptlets.

    JSP Scriptlets:
    JSP allows to write block of Java code within scriptlet tags which are <% some Java code goes here %>.It does not contribute anything to HTML page and Java code is evaluated each time when JSP loads.

    Here is an example which shows use of JSP Comments,Expression,Declaration and Scriptlet:


    No comments

    Post Top Ad

    Post Bottom Ad