The following article describes Scripting Elements in JSP.

There are three types of scripting elements in a JSP.

Scriptlet: A scriptlet is a block of Java code that is executed when the JSP page is processed. Scriptlets are enclosed in <% and %> tags, and can contain any valid Java code, including variable declarations, loops, conditionals, and method calls. For Example.

<%
int count = 0;
for (inti = 0; i< 10; i++) {
count += i;
  }
%>

Expression: An expression is a dynamic value that is inserted into the HTML output generated by the JSP. Expressions are enclosed in <%= and %> tags, and can contain any valid Java expression, including method calls and variable references. For Example.

<p>The current time is <%= new java.util.Date() %>.</p>

Declaration: A declaration is used to declare instance or class-level variables and methods that can be accessed throughout the JSP page. Declarations are enclosed in <%! and %> tags, and can contain any valid Java code, including variable declarations, method definitions, and class definitions. For Example.

<%! int count = 0; %>
<%
count++;
%>
<p>The count is <%= count %>.</p>

In summary, scriptlets, expressions, and declarations are the three types of scripting elements in a JSP, each used for different purposes such as executing Java code, inserting dynamic values into HTML output, and declaring variables and methods.


Further Reading

Spring Framework Practice Problems and Their Solutions

Java Practice Exercise

programmingempire

Princites