Key Acronyms JSP = JavaServer Pages |
Page Lifecycle 1. Page Translation |
||||||||||||||||||||||||||||
BASIC SYNTAX Directive Elements (translation phase) <%@ page ... %> - <jsp:directive.page .. /> in XML Scripting Elements <% ...; %> - script-let - <jsp:scriptlet> in XML <%= ... %> - expression - <jsp:expression> in XML <%! ...; %> - declaration - <jsp:declaration> in XML <%-- ... --%> - comment - <!-- ... --> in XML ${ <EL expression> } - JSTL 1.0/JSP2.0 |
|||||||||||||||||||||||||||||
Implicit objects (note not available in declarations) application - ServletContext |
|||||||||||||||||||||||||||||
Page Directive Attributes autoFlush - Boolean indicating whether buffer should flush when full (true) |
|||||||||||||||||||||||||||||
Action Elements/Tags (request processing phase) <jsp:useBean id="beanName" class="com.classes.BeanClass" [scope="page"]/> |
|||||||||||||||||||||||||||||
JSTL libraries http://java.sun.com/jsp/jstl/core (c) http://java.sun.com/jsp/jstl/xml (x) http://java.sun.com/jsp/jstl/fmt (fmt) http://java.sun.com/jsp/jstl/sql (sql) http://java.sun.com/jsp/jstl/fn (fn) JSTL functions (JSTL 1.1) c:out(value) c:param(name, value) c:forEach(var, items, varStatus) c:forToken c:url c:import(url) fmt:formatNumber(value, pattern) fmt:parseNumber fmt:formatDate fmt:parseDate fmt:timeZone fmt:setTimeZone fmt:setLocale(value) fmt:bundle(basename) fn:contains(string, substring) fn:containsIgnoreCase(string, substring) fn:endsWith(string, suffix) fn:escaleXml(string) fn:indexOf(string, substring) fn:join(array, separator) fn:length(item) fn:replace(string, before, after) fn:split(string, separator) fn:startsWith(string, prefix) fn:substring(string, begin, end) fn:substringAfter(string, substring) fn:substringBefore(string, substring) fn:toLowerCase(string) fn:toUpperCase(string) fn:trim(string) sql:setDataSource(var,driver,url) sql:query(var,datasource) sql:update sql:transaction(dataSource) x:parse(source, var) x:out(select) x:transform(source, xslt) |
|||||||||||||||||||||||||||||
PageContext methods setAttribute(name, valueObject) |
Variable scopes jsp:usebean Servlet =========== ======= page PageContext.PAGE_SCOPE request PageContext.REQUEST_SCOPE session PageContext.SESSION_SCOPE application PageContext.APPLICATION_SCOPE |
||||||||||||||||||||||||||||
Custom tag interfaces Tag - base class for simple tags Tag methods (in order of execution) setPageContext() - called by the container
|
|||||||||||||||||||||||||||||
Expression Language - Literals true, false, 5, -5, 5.5, 5.5E5, "string", 'string', null Expression Language - Operators +,-,*,/,%,==,!,!=,<,>,<=,>=,&&,||,(,) Expression Language - Equivalent JSP expressions {$list[1]} == <%= list.elementAt(1) %>
{$map.name} == <%= map.get("name") %>
{$map['name']} == <%= map.get("name") %>
{$map[name]} == <%= map.get(pageContext.findAttribute("name")) %>
{$bean.property} == <%= bean.getProperty() %>
{$pageContext.response} == <%= pageContext.getResponse() %>
{$pageContext.session} == <%= pageContext.getSession() %>
{$pageContext.context} == <%= pageContext.getServletContext() %>
{$pageContext.request.requestURI} == <%= pageContext.getRequest().getRequestURI() %>
{$param.name} == <%= request.getParameter("name") %>
{$paramValues.name} == <%= request.getParameterValues("name") %>
{$header.name} == <%= request.getHeader("name") %>
{$headerValues.name} == <%= request.getHeaderValues("name") %>
{$pageScope.cart.count} == <%= pageContext.getAttribute("cart", PageContext.PAGE_SCOPE).getCount() %>
{$requestScope.cart} == <%= pageContext.getAttribute("cart", PageContext.REQUEST_SCOPE) %>
{$sessionScope.cart} == <%= pageContext.getAttribute("cart", PageContext.SESSION_SCOPE) %>
{$applicationScope.cart} == <%= pageContext.getAttribute("cart", PageContext.APPLICATION_SCOPE) %>
{$mytl:myfn()} - calls the myfn() function of the mytl tag library
EL functions are code as public static methods and identified using the function element of the TLD. |
|||||||||||||||||||||||||||||
Tag Library Descriptor (META-INF/taglib.tld)
|
|||||||||||||||||||||||||||||
WAR structure /WEB-INF/web.xml |
|||||||||||||||||||||||||||||
See also our guide to servlets |
|||||||||||||||||||||||||||||
© 2005 i-Lab Limited