Now, we'll break down JSPs into some detail
Actions
<action:actionName>
- Actions may affect the current out stream and use, modify and/or create objects.
- Actions may depend on the details of the specific request object received by the JSP page.
- Some actions are standard, and are included with the container, new actions
can be created using the taglib directive (next lecture)
Expressions
<%= expression %>
- the value as a String is printed out to the JspWriter
- Can also be written in XML sytax as
<jsp:expression>
expression
</jsp:expression>
- Think of it as
out.println(expression)
- Example: Current Time: <%= new java.util.Date() %>
Scriptlets
<% code %>
- Can also be written in XML sytax as
<jsp:scriptlet>
code
</jsp:scriptlet>
- Run in the _jspService method
- Can contain any Java code
- Has access to the same predefined variables as expressions
- Can make parts of a JSP conditional
Declarations
<%! code %>
- Can also be written in XML sytax as
<jsp:declaration>
code
</jsp:declaration>
- Inserted in the body of the servlet, outside of any existing code
- Declares variables accessible by all threads, the declaration is
placed outside the _jspService method.
- Do not generate any output
Comments
- HTML Comments (will be in the source sent to the client)
- Ex:
<!-- this goes -->
- JSP Comments (only put in Java source, stays on server)
- Ex:
<%-- JSP comment --%>
Escaping in JSPs
In scripting elements
- A literal %> is quoted as %\>
In template text
- A literal <% is quoted as <\%
In attributes
- A ' is quoted as \'
- A " is quoted as \"
- A \ is quoted as \\
- A %> is quoted as %\>
- A <% is quoted as %\>
Next lecture, we'll look a bit at the Expression Language as well.


