Overview of JSP Syntax Element
 
Scripting Elements
 
JSP scripting elements include the following categories of Java code snippets that can appear in a JSP page:
 
.declarations--
These are statements declaring methods or member variables that will be used in the JSP page. A JSP declaration uses standard Java syntax within the <%!...%> declaration tags to declare a member variable or method. This will result in a corresponding declaration in the generated servlet code.
For example:
<%! double f1=0.0; %>
 
.expressions--
These are Java expressions that are evaluated, converted into string values as appropriate, and displayed where they are encountered on the page. A JSP expression does not end in a semicolon, and is contained within <%=...%> tags.
For example:
<P><B> Today is <%= new java.util.Date() %>. Have a nice day! </B></P>
 
.scriptlets--
These are portions of Java code intermixed within the markup language of the page. A scriptlet, or code fragment, can consist of anything from a partial line to multiple lines of Java code. We can use them within the HTML code of a JSP page to set up conditional branches or a loop. A JSP scriptlet is contained within <%...%> scriptlet tags, using Java syntax.
For example:
<% if (pageBean.getNewName().equals("")) { %>
I don't know you.
<% } else { %>
Hello <%= pageBean.getNewName() %>.
<% } %>
 
.comments--
These are developer comments embedded within the JSP code, similar to comments embedded within any Java code. Comments are contained within <%--...--%> syntax.
For example:
<%-- Execute the following branch if no user name is entered. --%>
JSP comments are not visible when users view the page source from their browsers.