declaration Tag

declaration Tag

As you saw earlier, the Java code embedded in the JSP along with the HTML code is parsed and combined into the service() method of the servlet generated as a result of parsing the JSP. What if you needed to define variables or methods that need to be put outside the service() method? The declaration tag should be used in such cases.

Structure of the declaration Tag

The JSP declaration tag can be written in two ways:

 <%!  // java variables instantiated here %> or <jsp:declaration> // java code </jsp:declaration> 

The declaration tag is one of the simplest tags available in JSP:

 <%!  int myGlobalVar = 0; ClassA myclassA - new ClassA(); %> 

or

 <jsp:declaration>  int myGlobalVar = 0; ClassA myclassA - new ClassA(); </jsp:declaration> 

Including the two Java statements within the declaration tag ensures that when the servlet for the JSP is generated, the two Java statements will be placed outside the service() method.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net