Interview Question in JSP


 

Interview Question :: What is a Declaration?

 What is a Declaration?

by ksk
VoteNowAnswers to "What is a Declaration?"

 A declaration declares one or more variables or methods for use later in the JSP source file.

A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as they are separated by semicolons. The declaration must be valid in the scripting language used in the JSP file. 
 
<%! somedeclarations %>
<%! int i = 0; %>
<%! int a, b, c; %>
by ksk

Declaration in JSP is way to define global java variable and method. This java variable method in declaration can be access normally. Normally declaration does not produce any output, and access of this code is also limited. The declaration code does not reside inside service method of JSP. Declaration we use method to convert null convert of string in JSP.

We can see declaration code is not used to produce any direct output; it is used for reusable code.

by ksk