Declaration tag in JSP

JSP provide

1.Scriplet tag
2.Expression tag
3.Declaration tag

Declaration tag


In Declaration tag you can write method.
and you can also define variable.

syntax:

1
2
3
4
5
6
 
<%!
 
//here You can write method
 
%>

Example of Declaration tag


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
<%@ page language="java"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
 
<%!
 
 
String website="www.javaforlearn.com";
 
//defining method
public String  getAuthor()
{
	return "Bhavesh Lakhani";
}
 
%>
 
 
 
<%
 
out.println(website+" Provide tutorial to learn java "+"<br>");
 
//calling java method
 
out.println("Author name: "+getAuthor());
 
 
%>
 
</body>
</html>

Accessing JSP in Browser
output-declaration-tag

Leave a Reply

Your email address will not be published. Required fields are marked *