3. JSP Scriptlet tag


JSP Hello World Example :Previous                                                             Next: JSP Declaration Tag

JSP Scriptlet tag

Scriptlet tag contains the any no. of java code statements. It may contain variables declaration or valid expressions. When JSP is translated into servlet, java code written in the scriplet tag is moves to the _jspService() method by web container.

Syntax: <% java code %> 
Note: Variable and methods declare in scriplet 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>

Output:


JSP Hello World Example :Previous                                                             Next: JSP Declaration Tag