Jsp Scripting tags
Jsp Scripting elements are 3types
Scriptlet tag
· scriptlet tags are used write java code within the jsp page.
While in the translation page jsp container moves the statements enclosed in scriptlet tag to _jspService() method .
While in the translation page jsp container moves the statements enclosed in scriptlet tag to _jspService() method .
· For each client’s request
the _jspService() method gets invoked, so the code inside Scriptlet tag executes
for every request .
· Since the code inside scriptlet tag is a java code it must end with a
semicolon(;)
syntax:
<% java source code %>
Example:
<% out.print("Hello
welcome to jsp"); %>
Expression tag
·
Expression tag evaluates the expression placed in it and
converts the result into String.
·
The code placed within
expression tag is written to the output stream of the response. So you need not
write out.print() to write data.
·
It is mainly used to print the values of
variable or method.
syntax:
<%= statement
%>
Example1:
<%= "welcome
to jsp" %>
Example2:
<%= a+b
%>
Declaration tag
·
The JSP declaration
tag is used to declare variables and methods.
·
The code written
inside the jsp declaration tag is placed outside the service() method of auto
generated servlet. So it doesn't get memory at each request
syntax:
<%! statement %>
Example:
<%!
String name="java for job"; %>