
Play Store Application link – Advance java – in 15 steps – Apps on Google Play
Learn with our youtube video –
Tag Type | Syntax | Purpose |
---|---|---|
Scriplet tags | <% code %> | Used to embed Java code directly into a JSP page. The code within a scriplet tag is executed every time the JSP page is requested. |
Expression tags | <%= expression %> | Used to include the result of an expression in a JSP page. The expression within an expression tag is evaluated and the result is included in the output. |
Declaration tags | <%! code %> | Used to declare class-level variables and methods in a JSP page. The code within a declaration tag is inserted into the _jspService() method of the generated servlet. |
Directive tags | <%@ directive %> | Used to provide information to the JSP container, such as importing classes or setting the content type. Directive tags begin with <%@ and are typically used to set page-level properties. |
JSP Action Tags | <jsp: tag > | These are internal tags of JSP, used to simplifies common scenarios using tags and provides dynamic generation of content. |
1- Scriplet tag:
<html>
<body>
<%
int x = 5;
int y = 10;
int result = x + y;
%>
<h2>The result of <%= x %> + <%= y %> is <%= result %></h2>
</body>
</html>
2- Expression tag:
<html>
<body>
<%
int x = 5;
int y = 10;
int result = x + y;
%>
<h2>The result is <%= result %></h2>
</body>
</html>
3- Declaration tag:
<html>
<body>
<%!
int calculateSum(int a, int b) {
return a + b;
}
%>
<%
int x = 5;
int y = 10;
int result = calculateSum(x, y);
%>
<h2>The result of <%= x %> + <%= y %> is <%= result %></h2>
</body>
</html>
4- Directive tag:
[A] page directive
<%@ page import="class" %>
[B] Include directive
<%@ include file="jsp/html file" %>
[B] taglib directive
<%@ taglib prefix="short name to refer tag" uri="tag url" tagdir="tag directory" %>
5- JSP Action tag:
These are internal tags of JSP, used to simplifies common scenarios using tags and provides dynamic generation of content.
<jsp: tag > </jsp:tag>