Working with Scripting Tags :
JSP Scripting Tags allow a java programmer to add a script code into the java code of a JSP. In most of the cases java is the scripting language used to build a JSP page. There are many types of scripting tag:
Types of Scripting Tags:
There are mainly three JSP scripting tags:
- The Scriptlet Tag: This tag allow you
to declare variables, that you can use later in JSP page. It is also allow you
to write the script code for implementing the _jspService method. A JSP
scriptlet is used to contain any code fragment that is valid for the scripting
language used in a page.
The syntax for a scriptlet is as follows:
<%
script code
%>Example:
<html>
<body>
<%
for (int i=0; i<10;i++)
{
out.println(i);
}
%>
</body>
</html> The Declarative Tag: This tag allows you to declare instance and class variable and implement class methods such as jspInit and jspDestroy. JSP declaration is used to declare variables and methods in a page's scripting language.
The syntax for a declaration is as follows:
<%!
script code
%>Example:
<%!
int i, j;
int fun (int i)
{
return i;}
%>
<%i=1;>
<%j=fun (i);%>
<%out.println(j);%>The Expression Tag: Through this tag we show the resultant value. The expression tag places in the out. print method during the translation stage of the JSP lifecycle.
A JSP expression is used to insert the value of a scripting language expression, converted into a string, into the data stream returned to the client. When the scripting language is the Java programming language, an expression is transformed into a statement that converts the value of the expression into a String object and inserts it into the implicit out object.
The syntax for an expression is as follows:
<%=
script code
%>Example:
<%! int count; %>
<html> <body>
<% count++ %>
This page is requested by <%=count%> number of users till now.
</body>
</html>


Join the conversation! Your thoughts help the community grow.