What is JSP declaration?

By: Karthik  

Answer: JSP Decleratives are the JSP tag used to declare variables. Declaratives are enclosed in the <%! %> tag and ends in semi-colon. You declare variables and functions in the declaration tag and can use anywhere in the JSP. Here is the example of declaratives:

<%@page contentType="text/html" %>

<html>

<body>

<%!
int cnt=0;
private int getCount(){
//increment cnt and return the value
cnt++;
return cnt;
}
%>

<p>Values of Cnt are:</p>

<p><%=getCount()%></p>

</body>

</html>





Most Viewed Articles (in Interview )

What types of comments are available in the JSP?

Interview Question: Can i map more than one table in a CMP?

How to define an Abstract class?

Explain the new Features of JDBC 2.0 Core API?

Question: What is a Hidden Comment in JSP?

What is the difference between Session Bean and Entity Bean?

Differentiate between .ear, .jar and .war files.

Tell me something about J2EE component?

What do you understand by a J2EE module?

Question: How would you go about analyzing performance of an application?

Question: How is the MVC design pattern used in Struts framework?

Question: What is the directory structure of a web application?

Question: Explain the life-cycle methods in JSP?

Interview Question: What is local interface. How values will be passed?

Interview Question: What is the difference between JavaBean and EJB?

Latest Articles (in Interview)

Comment on this tutorial