Home Tutorial Java Jsp DECLARATION IN JSP

 
 

DECLARATION IN JSP
Posted on: June 16, 2010 at 12:00 AM
Advertisement
In this Section, we will discuss about declaration of variables & method in JSP using declaration tags.

DECLARATION IN JSP

In this Section, we will discuss about declaration of variables & method in JSP using declaration tags.

Using Declaration Tag, you can declare any number of variables & methods , as long as you end each declaration with a semicolon. The declaration must be valid in the Java programming language.

Point to remember before Declaration  :

  • Declaration must be end with semicolon .
  • You can use those variables & methods directly in your JSP without declaring , which are already declared in package imported using    <@ page> directive.

Note :- The scope of the declaration is JSP page  means  it is valid only in JSP page & any of its static included files.The dynamic files included with <jsp:include>, does not comes inside the scope of declaration.

Syntax :

    <%! declaration; [ declaration; ]+ ... %>   

Example :

<%@ page import="java.util.*" %>

<HTML>

<BODY>

<!-- Declaring variable & method -->

<%!

Date theDate = new Date();

Date getDate()

{

System.out.println( "In getDate() method" );

return theDate;

}

%>

Hello! The time is now <%= getDate() %>

</BODY>

</HTML>

OUTPUT :

Download Source Code

Advertisement

Related Tags for DECLARATION IN JSP:


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: June 16, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com