JavaSercer Pages The class has two instance variables, (Mambo hosting)

JavaSercer Pages The class has two instance variables, name and value, and the corresponding setter methods. The most interesting method is the doEndTag( ) method. This method first uses the findAncestorWithClass( ) method to try to locate the enclosing EncodeURLTag instance. Note that this is not the class name used as the argument value. Instead, the ParamParent interface is used. The reason is that the action is supported in the body of other actions besides , such as the action. The ParamParent interface is implemented by all tag handlers for actions that can contain nested actions: package com.ora.jsp.tags.generic; public interface ParamParent { void setParam(String name, String value); } The interface defines one method: the setParam( ) method. This is the method the nested ParamTag tag handler uses to communicate with its parent. For each nested action, the setParam( ) method gets called when the parent’s action body is processed. The name and value for each action are accumulated in the parent tag handler, ready to be used when the parent’s doEndTag( ) method is called. Example 16.4 shows the setParam( ) and doEndTag( ) methods implemented by the EncodeURLTag class. Example 16.4. EncodeURLTag … private Vector params; … public void setParam(String name, String value) { if (params == null) { params = new Vector( ); } Param param = new Param(name, value); params.addElement(param); } public int doEndTag( ) throws JspException { StringBuffer encodedURL = new StringBuffer(url); if (params != null && params.size( ) > 0) { encodedURL.append(’?'); boolean isFirst = true; Enumeration e = params.elements( ); while (e.hasMoreElements( )) { Param p = (Param) e.nextElement( ); if (!isFirst) { encodedURL.append(’&'); } encodedURL.append(p.getName( )).append(’='). append(p.getValue( )); isFirst = false; } } try { HttpServletResponse res = (HttpServletResponse) pageContext.getResponse( ); JspWriter out = pageContext.getOut( ); out.print(res.encodeURL(encodedURL.toString( ))); } catch (IOException e) {} return SKIP_BODY; } In setParam( ), the parameter name and value are saved as instances of a simple value holder class named Param, held in a Vector. In the doEndTag( ) method, each parameter’s name/value pair is added to the URL before the complete URL is encoded to support session tracking through URL rewriting. If you don’t remember what all of this means, you can refresh your memory by looking at Chapter 8 again. 16.5 Creating New Variables Through Actions Actions can also cooperate through objects available in the standard JSP scopes (page, request, session, and application). One example of this type of cooperation is illustrated by the three standard JSP actions: , , and . The action creates a new object and makes it available in one of the JSP scopes. The other two actions can then access the properties of the object by searching for it in the scopes. Besides making the object available in one of the scopes, the action also makes it available as a scripting variable, so it can be accessed by scripting elements in the page. page 223
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra j2ee hosting services

Comments are closed.