Master java skills

Declaration Tag

JSP Declaration Tag is used to declare variables and methods.

Syntax of jsp declaration tag

<%! variable or method %>

Declaration tag example

Declaration tag that declares a String variables.

<html>  
<body>  
    <%! String name = "Arjun"; 
        int i = 10; %>  
    <%= "The name is:" + name %> 
    <br>
    <%= "The value of i is:" + i %>  
</body>  
</html>  

Output

Declaration tag that declares a method

<html>
<body>
	<%!   
	int multiply(int num1, int num2){  
		return num1 * num2;  
	}
	%>
	<%= "Multiplication of 10 and 20 = " + multiply(10, 20) %>
</body>
</html>

Output