1 18 19 package org.apache.struts.taglib.logic; 20 21 import java.io.IOException ; 22 import java.net.MalformedURLException ; 23 import java.util.Map ; 24 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.TagSupport ; 28 29 import org.apache.struts.util.MessageResources; 30 import org.apache.struts.taglib.TagUtils; 31 32 37 public class RedirectTag extends TagSupport { 38 39 41 44 protected String anchor = null; 45 46 public String getAnchor() { 47 return (this.anchor); 48 } 49 50 public void setAnchor(String anchor) { 51 this.anchor = anchor; 52 } 53 54 57 protected String forward = null; 58 59 public String getForward() { 60 return (this.forward); 61 } 62 63 public void setForward(String forward) { 64 this.forward = forward; 65 } 66 67 70 protected String href = null; 71 72 public String getHref() { 73 return (this.href); 74 } 75 76 public void setHref(String href) { 77 this.href = href; 78 } 79 80 83 protected static MessageResources messages = 84 MessageResources.getMessageResources( 85 "org.apache.struts.taglib.logic.LocalStrings"); 86 87 90 protected String name = null; 91 92 public String getName() { 93 return (this.name); 94 } 95 96 public void setName(String name) { 97 this.name = name; 98 } 99 100 104 protected String page = null; 105 106 public String getPage() { 107 return (this.page); 108 } 109 110 public void setPage(String page) { 111 this.page = page; 112 } 113 114 118 protected String action = null; 119 120 public String getAction() { 121 return (this.action); 122 } 123 124 public void setAction(String action) { 125 this.action = action; 126 } 127 128 129 133 protected String module = null; 134 135 public String getModule() { 136 return (this.module); 137 } 138 139 public void setModule(String module) { 140 this.module = module; 141 } 142 143 146 protected String paramId = null; 147 148 public String getParamId() { 149 return (this.paramId); 150 } 151 152 public void setParamId(String paramId) { 153 this.paramId = paramId; 154 } 155 156 159 protected String paramName = null; 160 161 public String getParamName() { 162 return (this.paramName); 163 } 164 165 public void setParamName(String paramName) { 166 this.paramName = paramName; 167 } 168 169 172 protected String paramProperty = null; 173 174 public String getParamProperty() { 175 return (this.paramProperty); 176 } 177 178 public void setParamProperty(String paramProperty) { 179 this.paramProperty = paramProperty; 180 } 181 182 185 protected String paramScope = null; 186 187 public String getParamScope() { 188 return (this.paramScope); 189 } 190 191 public void setParamScope(String paramScope) { 192 this.paramScope = paramScope; 193 } 194 195 198 protected String property = null; 199 200 public String getProperty() { 201 return (this.property); 202 } 203 204 public void setProperty(String property) { 205 this.property = property; 206 } 207 208 211 protected String scope = null; 212 213 public String getScope() { 214 return (this.scope); 215 } 216 217 public void setScope(String scope) { 218 this.scope = scope; 219 } 220 221 224 protected boolean transaction = false; 225 226 public boolean getTransaction() { 227 return (this.transaction); 228 } 229 230 public void setTransaction(boolean transaction) { 231 this.transaction = transaction; 232 } 233 234 238 protected boolean useLocalEncoding = false; 239 240 public boolean isUseLocalEncoding() { 241 return useLocalEncoding; 242 } 243 244 public void setUseLocalEncoding(boolean b) { 245 useLocalEncoding = b; 246 } 247 248 250 255 public int doStartTag() throws JspException { 256 257 return (SKIP_BODY); 258 259 } 260 261 266 public int doEndTag() throws JspException { 267 268 this.doRedirect(this.generateRedirectURL()); 269 270 return (SKIP_PAGE); 271 272 } 273 274 279 protected String generateRedirectURL() throws JspException { 280 Map params = 281 TagUtils.getInstance().computeParameters( 282 pageContext, 283 paramId, 284 paramName, 285 paramProperty, 286 paramScope, 287 name, 288 property, 289 scope, 290 transaction); 291 292 String url = null; 293 try { 294 url = 295 TagUtils.getInstance().computeURLWithCharEncoding( 296 pageContext, 297 forward, 298 href, 299 page, 300 action, 301 module, 302 params, 303 anchor, 304 true, 305 useLocalEncoding); 306 307 } catch (MalformedURLException e) { 308 TagUtils.getInstance().saveException(pageContext, e); 309 throw new JspException ( 310 messages.getMessage("redirect.url", e.toString())); 311 } 312 313 return url; 314 } 315 316 322 protected void doRedirect(String url) throws JspException { 323 HttpServletResponse response = 324 (HttpServletResponse ) pageContext.getResponse(); 325 326 try { 327 response.sendRedirect(url); 328 329 } catch (IOException e) { 330 TagUtils.getInstance().saveException(pageContext, e); 331 throw new JspException (e.getMessage()); 332 } 333 } 334 335 338 public void release() { 339 340 super.release(); 341 anchor = null; 342 forward = null; 343 href = null; 344 name = null; 345 page = null; 346 action = null; 347 paramId = null; 348 paramName = null; 349 paramProperty = null; 350 paramScope = null; 351 property = null; 352 scope = null; 353 354 } 355 356 } 357 | Popular Tags |