There are three scripting language elements:
declarations, scriptlets, expressions.
In advanced Java, specifically in JavaServer Pages (JSP), there are three types of scripting elements:
- Declarations: Declarations are used to declare variables or methods that can be used later in the JSP file. They are defined using the
<%! %>
syntax.Example:jsp<%!
int myVariable = 10;
void myMethod() {
// some code
}
%>
- Scriptlets: Scriptlets are used to embed Java code directly into the HTML content of a JSP page. They are defined using the
<% %>
syntax.Example:jsp<%
String message = "Hello, World!";
out.println(message);
%>
- Expressions: Expressions are used to embed Java expressions directly into the HTML content, and they are evaluated, converted to a string, and inserted in the place where the expression appears. They are defined using the
<%= %>
syntax.Example:jsp<p>Current date and time: <%= new java.util.Date() %></p>
These scripting elements allow developers to mix Java code with HTML in JSP pages, providing a dynamic and flexible way to generate web content.