1 16 17 18 package org.apache.struts.webapp.example2; 19 20 21 import javax.servlet.http.HttpSession ; 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 26 34 35 public final class CheckLogonTag extends TagSupport { 36 37 38 40 41 44 private String name = Constants.USER_KEY; 45 46 47 50 private String page = "/logon.jsp"; 51 52 53 55 56 59 public String getName() { 60 61 return (this.name); 62 63 } 64 65 66 71 public void setName(String name) { 72 73 this.name = name; 74 75 } 76 77 78 81 public String getPage() { 82 83 return (this.page); 84 85 } 86 87 88 93 public void setPage(String page) { 94 95 this.page = page; 96 97 } 98 99 100 102 103 108 public int doStartTag() throws JspException { 109 110 return (SKIP_BODY); 111 112 } 113 114 115 122 public int doEndTag() throws JspException { 123 124 boolean valid = false; 126 HttpSession session = pageContext.getSession(); 127 if ((session != null) && (session.getAttribute(name) != null)) 128 valid = true; 129 130 if (valid) 132 return (EVAL_PAGE); 133 else { 134 try { 135 pageContext.forward(page); 136 } catch (Exception e) { 137 throw new JspException (e.toString()); 138 } 139 return (SKIP_PAGE); 140 } 141 142 } 143 144 145 148 public void release() { 149 150 super.release(); 151 this.name = Constants.USER_KEY; 152 this.page = "/logon.jsp"; 153 154 } 155 156 157 } 158 | Popular Tags |