Types of Scripting Elements
Expressions
Format:
<%= expression %>
Evaluated and inserted into the servlet's output. I.e.,
results in something like out.println(expression)
Scriptlets
Format:
<% code %>
Inserted verbatim into the servlet's _jspService method
(called by service)
Declarations
Format:
<%! code %>
Inserted verbatim into the body of the servlet class,
outside of any existing methods
21
JSP
www.corewebprogramming.com
JSP Expressions
Format
<%=
Java Expression
%>
Result
Expression evaluated, converted to String, and placed
into HTML page at the place it occurred in JSP page
That is, expression placed in _jspService inside out.print
Examples
Current time: <%= new java.util.Date() %>
Your hostname: <%= request.getRemoteHost() %>
XML compatible syntax
Java Expression
XML version not supported by Tomcat 3. Until JSP 1.2,
servers are not required to support it.
22
JSP
www.corewebprogramming.com
11