< Prev
Next >



JSP Scripting Elements



In JSP, there are three types of Scripting elements -



JSP Scriplets



A1.jsp
<html>

<head>
<title>JSP Scriplet Tag</title>
</head>


<body>
<% out.println("Saying hello from Java using Scriplet Tag"); %>
</body>

</html>


on executing this web page,



Note - The code in JSP Scriplets tag is automatically executed as soon as the JSP page loads.




JSP Declarations


In a JSP page, JSP declarations are only used to declare -
These variables and methods are part of a Java code within our JSP page and hence they are accessible to the rest of Java code within other scriplet tags on the same webpage. We can declare java variables and methods within JSP Declaration tags such as - <%! %>




A3.jsp
<html>

<head>
<title>JSP Declaration Tag</title>
</head>


<body>

<%! public void add()
{
int sum = 20 + 10;
}
%>

</body>

</html>





JSP Expressions


Java expressions result in a value, hence JSP Expression tags are used to enclose java expressions that yield a value to be printed on a JSP web page. The Java expressions are enclosed in within <%= %> tags.

Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
Python

Ad2