Scriptlet tag in JSP

Scriptlet tag contains any no. of Java code statements. It may contain variable declarations or valid expressions. When JSP is translated into a servlet, java code written in the Scriptlet tag is moved to the _jspService() method by the web container.

Syntax:

<% java code %>

Note: Variables and methods declared in the scriptlet tag are not of class-level declaration.

Example:

welcome.jsp

<html>
    <head>
        <title>Scriplet tag example</title>
    </head>
    <body>
        <%
            out.println("Sum of 10 and 20 = ");
            out.print(10 + 20);
        %>
    </body>
</html>

 

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>welcome.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>