package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import javax.servlet.*; /** The condition part of an if tag. *

* Taken from Core Servlets and JavaServer Pages * from Prentice Hall and Sun Microsystems Press, * http://www.coreservlets.com/. * © 2000 Marty Hall; may be freely used or adapted. */ public class IfConditionTag extends BodyTagSupport { public int doStartTag() throws JspTagException { IfTag parent = (IfTag)findAncestorWithClass(this, IfTag.class); if (parent == null) { throw new JspTagException("condition not inside if"); } return(EVAL_BODY_TAG); } public int doAfterBody() { IfTag parent = (IfTag)findAncestorWithClass(this, IfTag.class); String bodyString = getBodyContent().getString(); System.out.println("body String = " + bodyString); if (bodyString.trim().equals("128.198.60.174")) { System.out.println("Condition is set to * true *"); parent.setCondition(true); } else { System.out.println("Condition is set to * false *"); parent.setCondition(false); } return(SKIP_BODY); } }