/*
Title: Struts : Essential Skills (Essential Skills)
Authors: Steven Holzner
Publisher: McGraw-Hill Osborne Media
ISBN: 0072256591
*/
//ch08_01.jsp
<%@ taglib prefix="ch08" uri="WEB-INF/ch08_02.tld" %>
Inserting Text With Custom Tags
Inserting Text With Custom Tags
//ch08_04.jsp
<%@ taglib prefix="ch08" uri="WEB-INF/ch08_05.tld" %>
Handling Custom Tag Attributes
Handling Custom Tag Attributes
//ch08_07.jsp
<%@ taglib prefix="ch08" uri="WEB-INF/ch08_08.tld" %>
Creating Iterating Tags
Creating Iterating Tags
<%
String[] toppings = new String[]{ "Pepperoni", "Sausage", "Ham", "Olives" };
pageContext.setAttribute("toppings", toppings);
%>
Topping:
//ch08_10.jsp
<%@ taglib prefix="ch08" uri="WEB-INF/ch08_11.tld" %>
Creating Cooperating Tags
Creating Cooperating Tags
Topping:
//ch08_13.jsp
<%@ taglib prefix="ch08" uri="WEB-INF/ch08_15.tld" %>
Custom Tags and Variables
Custom Tags and Variables
<%
for(int loopIndex = 0; loopIndex < toppings.length; loopIndex++) {
out.println("Topping: " + toppings[loopIndex] + "
");
}
%>
package ch08;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
public class ch08_03 extends TagSupport
{
public int doEndTag() throws JspException
{
try {
pageContext.getOut().print("This text is from the custom tag.");
} catch (Exception e) {
throw new JspException(e.toString());
}
return EVAL_PAGE;
}
}
package ch08;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
public class ch08_06 extends TagSupport
{
String text;
public void setText(String s) {
text = s;
}
public int doEndTag() throws JspException
{
try {
pageContext.getOut().print(text);
} catch (Exception e) {
throw new JspException(e.toString());
}
return EVAL_PAGE;
}
}
package ch08;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class ch08_09 extends TagSupport{
private int iterationCounter = 0;
private String[] toppings = null;
public int doStartTag()
{
toppings = (String[]) pageContext.getAttribute("toppings");
return EVAL_BODY_INCLUDE;
}
public int doAfterBody() throws JspException
{
try{
pageContext.getOut().print(" " + toppings[iterationCounter] + "
");
} catch(Exception e){
throw new JspException(e.toString());
}
iterationCounter++;
if(iterationCounter >= toppings.length) {
return SKIP_BODY;
}
return EVAL_BODY_AGAIN;
}
}
package ch08;
import javax.servlet.jsp.tagext.*;
public class ch08_12 extends TagSupport
{
public int doStartTag() {
String[] toppings = new String[] {"Pepperoni", "Sausage", "Ham", "Olives"};
pageContext.setAttribute("toppings", toppings);
return SKIP_BODY;
}
}
Struts-Essential-Skills-ch08.zip( 1,443 k)