JSP Syntax:
1. Declarations
A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. (Don’t really see only use declarations, usually declare in the scriptlet.
<%! declaration; [ declaration; ]+ ... %>
<jsp:declaration>
//code fragment
</jsp:declaration>
<%! int i = 0; %>
<%! int a, b, c; %>
<%! Circle a = new Circle(2.0); %>
2. Scriptlet
A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.
<% code fragment %> //or
<jsp:scriptlet>
code fragment
</jsp:scriptlet>
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
3. Expression
The expression element can contain any expression that is valid according to the Java Language Specification but you cannot use a semicolon to end an expression.
<jsp:expression>
expression
</jsp:expression>
<html>
<head><title>A Comment Test</title></head>
<body>
<p>
Today's date: <%= (new java.util.Date()).toLocaleString()%>
</p>
</body>
</html>
Comment:
</%comment%/>
<%--comment--%>
Directives
A JSP directive affects the overall structure of the servlet class. It usually has the following form:
<%@ page ... %> Defines page-dependent attributes, such as scripting language, error page, and buffering requirements.
<%@ include ... %> Includes a file during the translation phase.
<%@ taglib ... %> Declares a tag library, containing custom actions, used in the page
Actions
<jsp:action_name attribute="value" />
JSP implicit objects
request, response, out, session, application, config, pageContext, page, Exception.
Interesting! jsp flow control with html
The if…else block starts out like an ordinary Scriptlet, but the Scriptlet is closed at each line with HTML text included between Scriptlet tags.
<%! int day = 3; %>
<% if (day == 1 | day == 7) { %>
<p> Today is weekend</p>
<% } else { %>
<p> Today is not weekend</p>
<% } %>
For loop:
“`
<%
for ( fontSize = 1; fontSize <= 3; fontSize++){ %>