pdf / 5-jsp+jstl
.pdfThe taglib Directive
<%@ taglib ( uri=”tagLibraryURI” | tagdir=”tagDir” ) prefix=”tagPrefix” %>
uri
путь до дескриптора
tagdir
путь до дескриптора. Должен начинаться с /WEB-INF/tags/
prefix
jsp:, jspx:, java:, javax:, servlet:, sun:,and sunw: зарезервированы
The include Directive
<%@ include file="relativeURLspec" %>
Implicit Includes
include-prelude
include-coda
Expression Language
Основан на:
•Available namespace (the PageContext attributes)
•Nested properties and accessors to collections
•Relational, logical and arithmetic operators.
•Extensible functions mapping into static methods in Java classes.
•A set of implicit objects
pageContext
pageScope
requestScope
sessionScope
applicationScope
param / paramValues
header / headerValues
cookie
initParam
Пример: ${param.productId}
Operators
Arithmetic Operators
Addition: + Substraction: - Multiplication: *
Division: / and div
Remainder (modulo): % and mod
Relational Operators
== and eq
!= and ne
< and lt
> and gt
<= and le
>= and ge
Logical Operators
&& and and
|| and or
! and not
Empty Operator - empty A
Conditional Operator - A ? B : C
Parentheses
Функции
<taglib>
...
<function>
<name>nickname</name> <function-class>mypkg.MyFunctions</function-class> <function-signature>
java.lang.String nickName(java.lang.String) </function-signature>
</function>
</taglib>
<h2>Dear ${my:nickname(user)}</h2>
JSP Configuration
jsp-config
taglib Задает явно соответствие между URI и путем на файловой системе
taglib-uri
taglib-location
jsp-property-group
Indicate that a resource is a JSP file (implicit).
Control disabling of EL evaluation.
Control disabling of Scripting elements.
Indicate page Encoding information.
Prelude and Coda automatic includes.
Indicate that a resource is a JSP document.
<jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>true</scripting-invalid> <is-xml>false</is-xml>
<include-prelude>/WEB-INF/jspf/prelude2.jspf</include-prelude> <include-coda>/WEB-INF/jspf/coda2.jspf</include-coda>
</jsp-property-group>
Standard Actions
<jsp:setProperty>
<jsp:getProperty>
<jsp:useBean>
Ищет объект с заданными id and scope. Если не находит создает бин с другим id
Можно задать alias уже созданному объекту
Аттрибуты
id
scope
class
beanName
Type
<jsp:useBean id=”connection” scope=“request” class=”com.myco.myapp.Connection”>
<jsp:setProperty name=”connection” property=”timeout” value=”33”> </jsp:useBean>
Порядок исполнения
Пытаемся найти по id and scope.
Если нашли приводим к заданному типы и инициализируем переменную ссылкой на данный объект. Завершаем исполнение
Не нашли
Если не заданны аттрибуты beanName или class: java.lang.InstantiationException
Задан класс: создаем новый объект дефолтным конструктором, исполняем тело jsp:useBean. Если не можем создать: java.lang.InstantiationException
Если задан beanName тогда вызываем instantiate of java.beans.Beans и исполняем тело jsp:useBean.
Standard Actions
●<jsp:include>
<jsp:include page=”urlSpec” flush="true|false">
{<jsp:param .... /> }* </jsp:include>
●<jsp:forward>
<jsp:forward page=”urlSpec”>
{<jsp:param .... /> }* </jsp:forward>
●<jsp:param>
<jsp:param name="name" value="value" />
●<jsp:plugin>
●<jsp:params>
●<jsp:fallback>
Standard Actions
<jsp:attribute>
<jsp:element name=”firstname”>
<jsp:attribute name=”name”>Susan</jsp:attribute> </jsp:element>
<firstname name=”Susan”/>
<jsp:element>
<jsp:body>
<jsp:invoke> (tag files only)
<jsp:invoke fragment=”frag2” var=”resultString” scope=”session”/>
<jsp:doBody> (tag files only)
<jsp:text>
<jsp:text><![CDATA[<mumble></foobar>]]></jsp:text>
<jsp:output> (JSP documents) omit-xml-declaration,
doctype-root-element, doctype-system, doctype-public