Programming Tutorials

JSP Declaratives

By: aathishankaran in JSP Tutorials on 2007-02-12  

While programming in jsp we have to know about the declaratives of jsp. Here the declaratives is explained for jsp files. For the beginners they should know how to declare the variables in jsp program. In this article its explained

In jsp program mainly three declaratives are used to embed the jsp code into html.

The three declaratives are:

<%@ %>
<%! %>
<% %>

Syntax of JSP Declaratives is:

<%!
//java code
%>

JSP Declaratives begins with <%! and ends %> with .We can embed any amount of java code in the JSP Declaratives. Variables and functions defined in the declaratives are class level and can be used anywhere in the JSP page.

Example:

<%@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>
<p><%=getCount()%></p>
<p><%=getCount()%></p>
<p><%=getCount()%></p>
<p><%=getCount()%></p>
<p><%=getCount()%></p> </body>
</html>

This program illustrates how to initialize the variables in jsp program. And the program is shows how to embed the jsp in html program. Here both <@% %> , <!% %>, and <% %> tags are used in this program.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in JSP )

Latest Articles (in JSP)