Declaration tag is one of the scripting elements in JSP.
This Tag is used for declare the variables. Along with this, Declaration Tag can also declare method and classes. Jsp initializer scans the code and find the declaration tag and initialize all the variables, methods and classes. JSP container keeps this code outside of the service method (_JSPService()) to make them class level variables and methods.
Syntax of JSP-Declaration Tag
Example of JSP Declaration Tag which initialise a string
Example of JSP Declaration Tag which initializes a method
Difference between the JSP Expression, Declarative and Scriptlet tags
- Expression tag: This tag contains a scripting language expression that is converted to a String and inserted where the expression appears in the JSP file. Because the value of an expression is converted to a String, you can use an expression within text in a JSP file. You cannot use a semicolon to end an expression.
- Declaration tag : This declares one or more variables or methods for use later in the JSP source file. It must contain at least one complete statement. You can declare any number of variables or methods within one declaration tag, but you have to separated them by semicolons. The declaration must be valid in the scripting language used in the JSP file.You can add method to declaration part.
- Scriptlet tag : You can declare variables in the script-let and can do any processing. All the Scriptlet go to inside service() method of the convert servlet.
- Multitape Nondeterministic Turing Machine simulator
- LOB Rules and Restrictions
- ML | Training Image Classifier using Tensorflow Object Detection API
- JSP Access Model
- TensorFlow 2.0
- Data Structures and Algorithms Online Courses : Free and Paid
- Interesting Facts in C Programming | Set 2
- Sum of an array using MPI
- What is the Role of Java in the IT Industry?
- Program for Gauss Siedel Method (Computational Mathematics)
- AI Model For Neurodegenerative Diseases
- Introduction to Model View View Model (MVVM)
- Check if the two given stacks are same
- Why Data Structures and Algorithms are "Must Have" for Developers and Where to learn them : Answered
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.