Advertisement



< 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.


Advertisement




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

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON and DJANGO


Advertisement