Documente Academic
Documente Profesional
Documente Cultură
Taguri JSP Proprii
Taguri JSP Proprii
Curs 3
Cristian Frăsinaru
acf@infoiasi.ro
Facultatea de Informatică
Universitatea ”Al. I. Cuza” Iaşi
Taguri JSP proprii
Exemple:
Procesarea unor formulare
Operaţii cu baze de date
Accesarea unor servicii, etc.
identifier(uri) - location
web.xml
<jsp-config>
<taglib>
<taglib-uri>
http://jakarta.apache.org/tomcat/example
</taglib-uri>
<taglib-location>
/WEB-INF/jsp/example-taglib.tld
</taglib-location>
</taglib>
</jsp-config>
Tehnologii avansate de programare – p.12/?
Tipuri de taguri
Simple
Cu atribute
Cu corp
Iterative
Imbricate
Care definesc variabile scriptice
Cooperante
Nu au conţinut
Sunt implementate folosind clasa SimpleTagSupport.
public SimpleTag extends SimpleTagSupport {
public void doTag() {
...
}
}
In fişierul descriptor:
<body-content>tagdependent|scriptless</body-content>
<prefix:outer-tag>
<prefix:inner-tag />
</prefix:outer-tag>
Exemplu:
<table>
<tr>
<td> <td/>
</tr>
</table>
<prefix:then>
JSP inclus daca expresia este adevarata
</prefix:then>
<prefix:else>
JSP inclus daca expresia este falsa
</prefix:else>
</prefix:if>
/WEB-INF/tags/salut.tag
<h1> Salut! </h1>
test.jsp
<%@ taglib tagdir="/WEB-INF/tags" prefix="h" %>
<html>
<h:salut />
</html>
taglib
include
tag
attribute
variable
Parametri
display_name
bodycontent="empty | scriptless | tagdependent"
dynamic-attributes
small_icon, large_icon
description
import
...
Parametri
name
required="true | false | yes | no"
rtexprvalue="true | false | yes | no"
description
type (implicit java.lang.String)
fragment="true | false | yes | no"
/WEB-INF/tags/salut.tag
<%@ attribute name="mesaj" required="true" %>
<%@ attribute name="nume" required="true" %>
<h1>
<%= mesaj %> <%= nume%>!
</h1>
test.jsp
<%@ taglib tagdir="/WEB-INF/tags" prefix="h" %>
<html>
<h:salut mesaj="Bine ai venit" nume="Ioane"/>
<h:salut mesaj="Hello" nume="folks"/>
</html>
Declararea
<%@ tag dynamic-attributes="atributeMap"%>
Trimiterea atributelor
<un:tag>
<jsp:attribute name="atributDinamic1">
valoareAtribut1
</jsp:attribute>
<jsp:attribute name="atributDinamic2">
valoareAtribut2
</jsp:attribute>
...
</un:tag>
/WEB-INF/tags/salut.tag
<jsp:doBody var="continut"/>
<%
String bc = (String) jspContext.getAttribute("continut");
bc = bc.toUpperCase();
%>
<h2>
<%= bc %> !
</h2>
test.jsp
<%@ taglib tagdir="/WEB-INF/tags" prefix="h" %>
<html>
<h:salut>
welcome
</h:salut>
</html>