<% ... %>
contains Java code
<%= value %>
inserts the value
of a Java expression into the HTML document
webapps
jan
jan/jsp
jan/WEB-INF
jan/WEB-INF/classes
jan/WEB-INF/classes
jan/jsp
HelloWWW
is referenced by
http://jan.newmarch.name:8080/jan/servlet/helloWWW
hello.jsp
is referenced by
http://jan.newmarch.name:8080/jan/jsp/hello.jsp
It is customary in a servlet to call the HttpServletRequest
request parameter
request
. In JSP, that is its name:
TOMCAT_HOME/webapps/jan/WEB-INF/classes
RequestDispatcher dispatcher = request.
getRequestDispatcher("/template.jsp");
if (dispatcher != null)
dispatcher.forward(request, response);
<jsp:forward page="/main.jsp" />
<%@ include file="relativeURL" %>
includes a file at that point, which could be another JSP page
<%! ... %>
such as
<%! int i = 0; %>
<%! public String f(int i) {
if (i < 3) return("...");
...
}
%>
<% ... >
<% if (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM) { %>
<p> Good Morning </p>
<% } else { %>
<p> Good Afternoon </p>
<% } %>
<%@ taglib prefix="c" url="http://java.sun.com/jsp/jstl/core" %>
defines the Core namespace "c".
Funtional Area | URI | Prefix | Example |
---|---|---|---|
Core | http://java.sun.com/jsp/jstl/core |
c
|
<c:tagname ...> |
XML processing | http://java.sun.com/jsp/jstl/xml |
x
|
<x:tagname ...> |
I18N capable formatting | http://java.sun.com/jsp/jstl/fmt |
fmt
|
<fmt:tagname ...> |
Database access (SQL) | http://java.sun.com/jsp/jstl/sql |
sql
|
<sql:tagname ...> |
Functions | http://java.sun.com/jsp/jstl/functions |
fn
|
fn:functionName(...) |
From The JavaTM Web Services Tutorial - Using JSTL
${ ... }
The EL (expression language) has a number of inbuilt variables including
pageContext
pageContext.request
param
paramValues
header
headerValues
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
fmt:setLocale
fmt:formatNumber
fmt:formatDate
fmt:timeZone
fmt:setTimeZone
fmt:parseDate
fmt:parseNumber
fmt:requestEncoding
fmt:bundle
Java Server Pages act as the presentation end of a backend web application. They allow a mix of HTML and Java in various ways