1 29 30 package com.caucho.jstl.el; 31 32 import com.caucho.el.Expr; 33 import com.caucho.jsp.PageContextImpl; 34 import com.caucho.jstl.NameValueTag; 35 import com.caucho.jstl.rt.CoreUrlTag; 36 import com.caucho.util.CharBuffer; 37 import com.caucho.util.L10N; 38 39 import javax.el.ELException; 40 import javax.servlet.http.HttpServletResponse ; 41 import javax.servlet.jsp.JspException ; 42 import javax.servlet.jsp.tagext.TagSupport ; 43 import java.io.IOException ; 44 45 public class RedirectTag extends TagSupport implements NameValueTag { 46 private static L10N L = new L10N(RedirectTag.class); 47 48 private Expr _valueExpr; 49 private Expr _contextExpr; 50 51 private CharBuffer _url; 52 53 56 public void setURL(Expr value) 57 { 58 _valueExpr = value; 59 } 60 61 64 public void setContext(Expr context) 65 { 66 _contextExpr = context; 67 } 68 69 72 public void addParam(String name, String value) 73 { 74 String encoding = this.pageContext.getResponse().getCharacterEncoding(); 75 76 CoreUrlTag.addParam(_url, name, value, encoding); 77 } 78 79 public int doStartTag() throws JspException 80 { 81 try { 82 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 83 84 String value = _valueExpr.evalString(pageContext.getELContext()); 85 String context = null; 86 87 if (_contextExpr != null) 88 context = _contextExpr.evalString(pageContext.getELContext()); 89 90 _url = UrlTag.normalizeURL(pageContext, value, context); 91 92 return EVAL_BODY_INCLUDE; 93 } catch (ELException e) { 94 throw new JspException (e); 95 } 96 } 97 98 public int doEndTag() throws JspException 99 { 100 String value = UrlTag.encodeURL(pageContext, _url); 101 102 try { 103 HttpServletResponse response; 104 ((HttpServletResponse ) pageContext.getResponse()).sendRedirect(value); 105 } catch (IOException e) { 106 throw new JspException (e); 107 } 108 109 return SKIP_PAGE; 110 } 111 } 112 | Popular Tags |