1 16 17 package org.apache.taglibs.request; 18 19 import java.util.*; 20 import javax.servlet.*; 21 import javax.servlet.http.*; 22 import javax.servlet.jsp.*; 23 import javax.servlet.jsp.tagext.*; 24 25 58 59 public class ParametersTag extends BodyTagSupport 60 { 61 private String name = null; 63 private HttpServletRequest req = null; 64 private Enumeration parameters = null; 66 private String parameter = null; 68 69 74 public final int doStartTag() throws JspException 75 { 76 req = (HttpServletRequest)pageContext.getRequest(); 78 79 if( name != null ) { 80 if( req.getParameter(name) != null ) 81 parameter = name; 82 } else { 83 parameters = req.getParameterNames(); 84 if( parameters == null || !parameters.hasMoreElements() ) 85 return SKIP_BODY; 86 parameter = (String )parameters.nextElement(); 87 } 88 if( parameter == null ) 89 return SKIP_BODY; 90 91 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 92 return EVAL_BODY_TAG; 93 } 94 95 100 public final int doAfterBody() throws JspException 101 { 102 if( name != null || !parameters.hasMoreElements() ) 104 return SKIP_BODY; 105 parameter = (String )parameters.nextElement(); 107 if( parameter == null ) 108 return SKIP_BODY; 109 return EVAL_BODY_TAG; 110 } 111 112 116 public final int doEndTag() throws JspException 117 { 118 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 119 try 120 { 121 if(bodyContent != null) 122 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 123 } catch(java.io.IOException e) 124 { 125 throw new JspException("IO Error: " + e.getMessage()); 126 } 127 return EVAL_PAGE; 128 } 129 130 135 public final void setName(String str) 136 { 137 name = str; 138 } 139 140 147 public final String getName() 148 { 149 return parameter; 150 } 151 152 159 public final String getValue() 160 { 161 String value = req.getParameter(parameter); 162 if( value == null ) 163 return ""; 164 return value; 165 } 166 167 } 168 | Popular Tags |