JSP - Declaration Tag
JSP Declaration
JSP के declaration tag में variables, methods और classes को declare किया जाता है | अगर किसी भी variable, methhod या class को इस्तेमाल करने से पहले उसे declare किया जाता है |
Syntax for JSP Declaration :
<% declaration %>OR
<jsp:declaration> declaration </jsp:declaration>
Example For Variable Declaration
Source Code :Output :<html> <head> <title>Declaration Tag - Variable Declaration</title> </head> <body> <%! int a = 1; %> <jsp:declaration> int b = 2; </jsp:declaration> <% out.print("Value of a : " + a + "<br />"); out.print("Value of b : " + b); %> </body> </html>
Value of a : 1 Value of b : 2
Example for Method Declaration
Source Code :Output :<html> <head> <title>Declaration Tag - Method Declaration</title> </head> <body> <%! String ConcatStr(String str1, String str2){ return str1 + str2; } %> <% out.print(ConcatStr("Hello", " World")); %> </body> </html>
Hello World
Example for Class Declaration
Source Code :Output :<html> <head> <title>Declaration Tag - Class Declaration</title> </head> <body> <%! public class MyClass{ public String myMethod(){ return "Hello World"; } } %> <% MyClass c = new MyClass(); out.print(c.myMethod()); %> </body> </html>
Hello World