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 44 45 public class QueryStringTag extends TagSupport 46 { 47 private String name = null; 48 49 54 public final int doEndTag() throws JspException 55 { 56 String query = 57 ((HttpServletRequest)pageContext.getRequest()).getQueryString(); 58 String value = null; 59 if( query != null ) { 60 StringTokenizer st = new StringTokenizer(query,"&"); 61 String prefix = name + "="; 62 String tmp = null; 63 while( st.hasMoreTokens() ) { 64 tmp = st.nextToken(); 65 if( tmp.startsWith(prefix) ) { 66 value = tmp.substring(prefix.length()); 67 break; 68 } 69 } 70 } 71 72 if( value == null ) 73 value = ""; 74 75 try { 76 pageContext.getOut().write("" + value); 77 } catch(Exception e) { 78 throw new JspException("IO Error: " + e.getMessage()); 79 } 80 81 return EVAL_PAGE; 82 } 83 84 89 public final void setName(String str) 90 { 91 name = str; 92 } 93 94 } 95 | Popular Tags |