In previous post we are sharing Declaration some of important point I am coding here also please see my attached video also for better understanding.

o   In a declaration we can define (rarely) a static block and a class also
o   In a Jsp we can have any number of declarations in any order.
o   Variables declared in a declaration are initialized to java default values.
o   Variables in a declaration retain their values across multiple requests because they are created
o   And initialized only once.






Expression:- An expression scripting element is an embedded java expression that is evaluated and converted to a text string. The resulting text string is placed in a jsp output, in the location at which the element appears. Expressions act as placeholders for java anguage expressions. An expression is evaluated each time the page is accessed, and its value is then embedded in the output HTML. An expression has the following form.

            <%=any vaid java expression %>

Examples:

<%=a+b %>
<%=new java.util.Date()%>

o   Expressions are inserted into the service method of the container- generated servlet.
o   We can have any number of expressions per page.
o   Embedded java expression should not be terminated with a semicolon.
o   We can print the value of any object or ay primitive data type to the output steam using an expression.
o   We can also use an expression in a jsp action attribute. In this case the value of the ex-Precision does not go to the output stream. It is evaluated at request time, and its value is assigned to the attribute. An Expression used in this way is known as request time attribute expression.




Scriptlet:- A scriptlet is used to include complete fragments of java code in the body of the JSP page. This scripting element differs from the other two in 2ways.

  •             It is not limited to the declaration of methods and variables.
  •             It does not generated a string output directly, as expressions do.


A scriptlet has the following form <% Any vakud free frin if hava cide %>
For example,

<%  int sum=0;
            For(int I=1;i<10;i++)
            Sum+=1;
%>
o   Scriptlet can be placed anywhere within the jsp body
o   We can place any number of scriptlets in a jsp.
o   Each scriptlet is inserted into the service method of the container – generated servlet in the given order.
o   The scriptlet is executed each time the page is requested.
o   As scriptlets contain any java code, they are typically used for embedding computing logic within a  jsp page.

Comments in a JSP page

In a jsp we can have 3 kinds of comments
            Java comments
            HTML comments
            JSP comments
In a declaration or a scriplet we can have single line or multi line java comments. HTML comment is of the form <!—Any commenting text à
A JSP comment is of the form <%-- Any commenting text --%>
Note:- A JSP comment is also known as a hidden comment as it is not displayed in the client.

Post a Comment

 
Top