What are JSP declarations? In how many ways we can write JSP declarations?


A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. You must declare the variable or method before you use it in the JSP file.

Following is the syntax for JSP Declarations −

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

You can write the XML equivalent of the above syntax as follows −

<jsp:declaration>
   code fragment
</jsp:declaration>

Following is an example for JSP Declarations −

<%! int i = 0; %>
<%! int a, b, c; %>
<%! Circle a = new Circle(2.0); %>

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

127 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements