JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration
| |
(Continued from antecedent part...)
Tag Aspect Amount Announcement Archetype - AttObjectTag.java
The tag class:
/**
* AttObjectTag.java
* Absorb (c) 2003 by Dr. Yang. All rights reserved.
*/
package ;
import java.util.*;
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import org.apache.taglibs.standard.lang.support.*;
public chic AttObjectTag extends TagSupport {
clandestine Cord booleanAtt = null;
clandestine Boolean booleanObject = null;
clandestine Cord stringAtt = null;
clandestine Cord stringObject = null;
clandestine Cord mapAtt = null;
clandestine Map mapObject = null;
accessible abandoned setBooleanAtt(String att) {
booleanAtt = att;
try {
booleanObject =
(Boolean) ExpressionEvaluatorManager.evaluate(
"booleanAtt", booleanAtt, java.lang.Boolean.class,
this, pageContext);
} bolt (JspException e) {
System.err.println(e.toString());
}
}
accessible abandoned setStringAtt(String att) {
stringAtt = att;
try {
stringObject =
(String) ExpressionEvaluatorManager.evaluate(
"stringAtt", stringAtt, java.lang.String.class,
this, pageContext);
} bolt (JspException e) {
System.err.println(e.toString());
}
}
accessible abandoned setMapAtt(String att) {
mapAtt = att;
try {
mapObject =
(Map) ExpressionEvaluatorManager.evaluate(
"mapAtt", mapAtt, java.util.Map.class,
this, pageContext);
} bolt (JspException e) {
System.err.println(e.toString());
}
}
accessible int doStartTag() {
JspWriter out = pageContext.getOut();
try {
out.println("booleanAtt = "+booleanAtt+"<br/>");
out.println("booleanObject = "+booleanObject+"<br/>");
out.println("stringAtt = "+stringAtt+"<br/>");
out.println("stringObject = "+stringObject+"<br/>");
out.println("mapAtt = "+mapAtt+"<br/>");
if (mapObject!=null) {
out.println("mapObject.size = "+mapObject.size()+"<br/>");
} abroad {
out.println("mapObject = null<br/>");
}
} bolt (IOException e) {
System.err.println(e.toString());
}
acknowledgment SKIP_BODY;
}
}
The TLD file:
<?xml version="1.0"?>
<!DOCTYPE taglib Accessible
"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">
<!-- HyTaglib.tld
Absorb (c) 2003 by Dr. Yang
-->
<taglib>
<tlib-version>1</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name> s Tag Library</short-name>
<tag>
<name>attObject</name>
<tag-class>.AttObjectTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>booleanAtt</name>
<required>false</required>
</attribute>
<attribute>
<name>stringAtt</name>
<required>false</required>
</attribute>
<attribute>
<name>mapAtt</name>
<required>false</required>
</attribute>
</tag>
</taglib>
The JSP page:
<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:hy="urn:jsptld:/WEB-INF/tlds/HyTaglib.tld" version="1.2">
<!-- AttObjectTagTest.jsp
Absorb (c) 2003 by Dr. Yang
-->
<jsp:directive.page contentType="text/html"/>
<html><body>
<p>Regular Strings:</p>
<hy:attObject booleanAtt="true" stringAtt="Hello world!"/>
<p>Literals:</p>
<hy:attObject booleanAtt="${false}" stringAtt="${ Yang }"/>
<p>Expressions:</p>
<hy:attObject booleanAtt="${1==1}"
stringAtt="${pageContext.request.method}"
mapAtt="${cookie}"/>
</body></html>
</jsp:root>
The output:
Regular Strings:
booleanAtt = true
booleanObject = true
stringAtt = Accost world!
stringObject = Accost world!
mapAtt = null
mapObject = null
Literals:
booleanAtt = ${false}
booleanObject = false
stringAtt = ${ Yang }
stringObject = Yang
mapAtt = null
mapObject = null
Expressions:
booleanAtt = ${1==1}
booleanObject = true
stringAtt = ${pageContext.request.method}
stringObject = GET
mapAtt = ${cookie}
mapObject.size = 0
Note that:
- The JSTL announcement appraisal apparatus is a changeless method, evaluate(), in
ExpressionEvaluationManager class, in org.apache.taglibs.standard.lang.support package.
- The announcement rules are identical to those declared in JSTL, because we
are using the aforementioned appraisal tool.
- If you bang "refresh" button on the browser, the mapObject.size will be 1,
because the affair id is stored in the cookie map.
|
booleanatt, println, attribute, string, stringatt, class, mapatt, version, mapobject, private, public, required, import, stringobject, pagecontext, system, tostring, catch, booleanobject, evaluate, false<, xmlns, world, attobject, boolean, expression, expressionevaluatormanager, jspexception, copyright, attobjecttag, taglib, , attribute <, < attribute, null private, name <, < jsp, err println, < name, private string, system err, < tag, < body, < required, attobject booleanatt, html <, required <, false< required, required false<, http java, string att, att try, public void, tag class, tag attribute, expressionevaluatormanager evaluate, class this, java sun, jsp tag, mapobject size, catch jspexception, sun com, null private string, class this pagecontext, < required false<, required false< required, standard lang support, taglibs standard lang, apache taglibs standard, tutorials tutorial notes, tag attribute handling, import javax servlet, org apache taglibs, jstl tutorials tutorial, |
Also see ...
javax.servlet.jsp.tagext.* Packagejavax.servlet.jsp.tagext.* is a Java amalgamation authentic in J2EE (I saw it in J2EE 1.3.1). This amalgamation contains:
i(Continued from antecedent part...)/iImplenting BodyTag Interface TraceTag.javaIn adjustment to affirm my compassionate of the IterationTag interface, I wrotethe af
i(Continued from antecedent part...)/iThe Servlet Chic TraceTagTest_jsp.javaAs we all understand that JSP pages are translated into Servlet classes beforeexecution.
Nested JSTL TagsWhen tags are nested, JSP tag addendum ability offers the adolescent tag anaccess to the ancestor tag by the setParent() adjustment call. You can yield advantage
i(Continued from antecedent part...)/iI am abiding you can apprehend this page, and accept what I am accomplishing with the loop. Warning, my "break" tag is not a absolutely breach statement. If there is any addi
This affiliate explains:How to change Bobcat 4.1.18 accession from using JDK 1.3.1 to using JDK 1.4.1.Compilation issues of using JavaBean classes in bearding packages.
i(Continued from antecedent part...)/iYou will get the afterward accumulation absurdity adage CacheBean is not resolvable: org.apache.jasper.JasperException: Clumsy to abridge chic for JSP
This affiliate explains:How to amount a JavaBean into JSP pages and dispense its properties. Compilation issues of using JavaBean classes in bearding packages.Setti
i(Continued from antecedent part...)/iIt s actual absorbing to see the Servlet chic translated from UseBean.jsp: package org.apache.jsp;import javax.servlet.*;import javax.
i(Continued from antecedent part...)/iIn this section, let s attending at some of the basal rules about ambience and gettingJavaBean properties:The setProperty aspect haveto be accura