1 18 package org.apache.struts.webapp.example; 19 20 21 import java.io.IOException ; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpSession ; 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 import org.apache.struts.config.ModuleConfig; 28 29 30 36 public final class CheckLogonTag extends TagSupport { 37 38 39 41 42 45 private String name = Constants.USER_KEY; 46 47 48 51 private static String LOGIN_PATH = "/Logon.do"; 52 53 54 57 private String page = LOGIN_PATH; 58 59 60 62 63 68 public int doStartTag() throws JspException { 69 70 return (SKIP_BODY); 71 72 } 73 74 75 82 public int doEndTag() throws JspException { 83 84 boolean valid = false; 86 HttpSession session = pageContext.getSession(); 87 if ((session != null) && (session.getAttribute(name) != null)) { 88 valid = true; 89 } 90 91 if (valid) { 93 return (EVAL_PAGE); 94 } else { 95 ModuleConfig config = 96 (ModuleConfig) pageContext.getServletContext().getAttribute( 97 org.apache.struts.Globals.MODULE_KEY); 98 99 try { 100 pageContext.forward(config.getPrefix() + page); 101 } catch (ServletException e) { 102 throw new JspException (e.toString()); 103 } catch (IOException e) { 104 throw new JspException (e.toString()); 105 } 106 107 return (SKIP_PAGE); 108 } 109 110 } 111 112 113 116 public void release() { 117 118 super.release(); 119 this.name = Constants.USER_KEY; 120 this.page = LOGIN_PATH; 121 122 } 123 124 } 125 | Popular Tags |