Home Jsp INTRODUCTION TO JSP DECLARATIVES
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

INTRODUCTION TO JSP DECLARATIVES

Advertisement
JSP Declaratives begins with <%! and ends %> with .

INTRODUCTION TO JSP DECLARATIVES

     

Syntax of JSP Declaratives are:

  <%!
  //java codes
   %>

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>

The above example prints the value of variable cnt.
To execute the code click below.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 13, 2008

Related Tutorials

Ask Questions?    Discuss: INTRODUCTION TO JSP DECLARATIVES   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
sajal
December 16, 2011
jsp

helpfull
k
December 20, 2011
su

super
aruna
June 24, 2012
java

i want how to execute the jsp prgm
DMCA.com