1 16 17 package org.apache.taglibs.request; 18 19 import javax.servlet.*; 20 import javax.servlet.http.*; 21 import javax.servlet.jsp.*; 22 import javax.servlet.jsp.tagext.*; 23 24 43 44 public class CookieTag extends TagSupport 45 { 46 private String name = null; 48 49 54 public final int doEndTag() throws JspException 55 { 56 String value = null; 57 58 Cookie cookie = null; 60 Cookie [] cookies = 61 ((HttpServletRequest)pageContext.getRequest()).getCookies(); 62 if( cookies != null ) { 63 for( int i = 0; i < cookies.length; i++ ) { 64 if( cookies[i].getName().equals(name) ) { 65 cookie = cookies[i]; 66 break; 67 } 68 } 69 } 70 if( cookie != null ) 71 value = cookie.getValue(); 72 73 if( value == null ) 74 value = ""; 75 76 try { 77 pageContext.getOut().write(value); 78 } catch(Exception e) { 79 throw new JspException("IO Error: " + e.getMessage()); 80 } 81 82 return EVAL_PAGE; 83 } 84 85 90 public final void setName(String str) 91 { 92 name = str; 93 } 94 95 } 96 | Popular Tags |