JSP Scriptlet Tag

tutorial and example
tutorial and example

JSP scriptlet tag allows you to insert programming logic inside JSP page. Hence, you can put valid Java code within scriptlet tags. Each Java statement must be followed by a semicolon.

Syntax: – <% Java code %>

Whatever the code written inside scriptlet tag <% %> is compiled as Java code. This code can be accessible anywhere inside the JSP page. Any number of Java statements and local variables can be inserted in scriptlet tag. Although, scriptlet doesn’t allow method declaration within it.

Example of JSP Scriptlet Tag

Here is a simple example of JSP scriptlet tag having a Java code within it.

index.jsp

Output:

Internal Procedure

Internally, JSP container inserts the content of scriptlet tag into the jspService() method.

Internal code: