3.1 Scripting Elements

Scripting Elements

There are 3 main Scripting elements

1. Scriptlet

Scriptletwill be used to write any valid java statements like local variables or any other java code. All the statements inside Scriptletmust be terminated with semicolon. All the statements inside the scriplet will be placed inside jspService method that is executed every time the JSP is invoked

<html>
<body>
<%
// This is a scriptlet.  Notice that the "date"
//variable we declare here is available in the
// embedded expression later on.
<%int count = 0;   %>       
 Page Count is  <% out.println(++count); %>
System.out.println( "Evaluating date now" );
java.util.Date date = new java.util.Date();
%>
Hello!  The time is now <%= date %>
</body>
</html>

 

2. Expressions

Expression is a short form of out.println().Expressions  are short form of jsp.All the expressions inside the jsp are placed inside the jspService() method.

<html>
<head>
<title>Insert title here</title>
</head>
<%
int count = 0;
%>
<body>
Page Count is  <%= ++count %>
</body>
</html>

 3.Declarations 

Declarations is used to write class level members ie instance/static variables and methods.

<html>
<head>
<title>Methods Declaration</title>
</head>
<body>
<%!int sum(int num1,int num2,int num3)
{return num1+num2+num3;}  %>
<%="Result is: "+ sum(10,40,50) %>
</body>
</html>
January 16, 2016

0 responses on "3.1 Scripting Elements"

Leave a Message

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

About Us

Pradeep Academy is an online & Training institute To make learning easy, interesting, affordable and accessible to millions of learners across the Globe.
To create an alternative learning platform, using a unique learning methodology of live online interactive courses along with 24x7 support. We aim to empower our customers with skills which will help them get an edge in their careers and improve their lives.

Contact Us

Address :

#Hosabelaku Building, 3417/13, Near TTMC Bus Stop,, 30 Feet Service Road,

Vijaya Nagar, Bengaluru, Karnataka 560040
Email : [email protected]
Ph No: +91 8660907231
Web: https://academy.pradeepit.com
top
© Pradeep Academy.  Design & Developed by