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.
Execute the example.

|
Current Comments
11 comments so far (post your own) View All Comments Latest 10 Comments:this is the project i hve to do in jsp platform
that estimation of leather product with inventory check
If anybody intrested to help me i will send u the detail description
This my MCA proj
Posted by sundari on Saturday, 02.9.08 @ 09:18am | #47662
i want to use resultSet object in javascript function. The function is called useing onchange="functionname()"
using jsp tags
Posted by kishore on Friday, 02.1.08 @ 17:20pm | #46864
have anyone heard about the tag called <taloginContble>.. what does it mean...if know, respond me ..
i hope u guys consider this and help me too..
Posted by dhinesh kumar on Monday, 01.14.08 @ 12:21pm | #45165
If someone can give more examples of all the concepts of jsp.
Posted by sam on Wednesday, 10.10.07 @ 17:10pm | #33008
Hi,
Plz inform the details of the Eclipse.
Posted by Krishna on Friday, 07.6.07 @ 10:04am | #20818
Hi,
I will be using 6230i phone as a modem connected to the computer via USB cable. U guys know to connect the apache tomcat v5.5 to the phone-modem. I know i need a interface to connect them together, but, cant managed to find it.
Hope u guys could help out.
thx.
Posted by Kobe on Thursday, 07.5.07 @ 12:51pm | #20758
download it from apachesoftware foundation
from apache.org
Posted by vivek kumar on Wednesday, 05.30.07 @ 19:19pm | #17744
I want to write JSP.net pages using visual basic on tomcat. how can i do it using directives? Can i use page to redirect to a application server url which in turn calls the .net code and all this happens over tomcat.
Posted by Tamboo on Wednesday, 05.16.07 @ 01:05am | #16044
Hi i want to capture am image from webcam using JSP code.Is it possible.Can we embed Swings code inside the JSP.Pls post me related topic
Posted by Login on Saturday, 03.17.07 @ 22:57pm | #12021
hello sir i want the complete usage of eclipse in real time pls inform the details of the eclipse
Posted by jagadeesh on Wednesday, 02.28.07 @ 21:43pm | #9972