JSP Elements
Scriptlet: Everything between <% and %> is a Scriptlet, which is just plain old java. Scriptlet’s can have variable declarations. But they are local variables.
Syntax: Scriptlet doesn’t add any additional character.
<% out.println(“Hi”); %>
Directive: A directive is a way for you to give special instructions to the container at the page translation time.
Syntax: Directive adds an additional character to the start of the element – the @ sign.
<%@ page import = ”java.util.*” %>
Expression: Expressions becomes the argument to out.print()
Syntax: Expression adds an additional character to the start of the element – an equal sign (=). Semicolon should be avoided at the end of the statement. No variable declarations are allowed.
<%= 50 %> Valid
<%= 50; %> Invalid (Semicolon not allowed)
<%= int i=5 %> Invalid (variable declaration not allowed)
Example:
<%= “Plus” %>
out.print(“Plus”);
NOTE:
All Scriptlet and expression code lands in a service method.
That means variables declared in a Scriptlet are always local variables.
Declaration: JSP declarations are for declaring instance members of the generated servlet class. That means both variables and methods.
Syntax: Declaration adds an additional character to the start of the element – an exclamation sign (!).
<%! int count = 0; %>
0 Comments:
Post a Comment
<< Home