JavaSercer Pages This is part of (Servlet hosting) the puzzle.
JavaSercer Pages This is part of the puzzle. However, a tag handler is usually interested only in finding a parent it’s been designed to work with. It would be nice to have a method that works its way up the hierarchy until it finds the parent of interest. That’s exactly what the findAncestorWithClass( ) method implemented by the TagSupport class does: public static final Tag findAncestorWithClass(Tag from, Class klass) { boolean isInterface = false; if (from == null || klass == null || (!Tag.class.isAssignableFrom(klass) && !(isInterface = klass.isInterface( )))) { return null; } for (;;) { Tag tag = from.getParent( ); if (tag == null) { return null; } if ((isInterface && klass.isInstance(tag)) || klass.isAssignableFrom(tag.getClass( ))) return tag; else from = tag; } } First of all, note that this is a static method. Consequently, it can be used even by tag handlers that implement the Tag interface directly, instead of extending the TagSupport class. The method takes two arguments: the tag handler instance to start searching from, and the class or interface of the parent. After making sure that all parameters are valid, it starts working its way up the nested tag handlers. It stops when it finds a tag handler of the specified class or interface and returns it. If the specified parent type is not found, the method returns null. This is all that’s needed to let a nested action communicate with its parent: the parent accessor methods, and the method that walks the action hierarchy to find the parent of interest. Example 16.3 shows how the ParamTag class uses this mechanism to find the enclosing EncodeURLTag instance. Example 16.3. The ParamTag Class package com.ora.jsp.tags.generic; import java.net.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class ParamTag extends TagSupport { private String name; private String value; public void setName(String name) { this.name = name; } public void setValue(String value) { this.value = value; } public int doEndTag( ) throws JspException { Tag parent = findAncestorWithClass(this, ParamParent.class); if (parent == null) { throw new JspException(”The param action is not ” + “enclosed by a supported action type”); } ParamParent paramParent = (ParamParent) parent; paramParent.setParam(name, URLEncoder.encode(value)); return EVAL_PAGE; } } page 222
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check professional tomcat hosting services