bannertag.java

来自「<Java网络程序设计 J2EE>随书源码」· Java 代码 · 共 44 行

JAVA
44
字号
package org.impact.stars.taglib.banner;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;import org.impact.stars.control.web.ProfileMgrWebImpl;import org.impact.stars.organizationmd.profilemgr.model.ExplicitInformation;/* * BannerTag * --------- * On hitting the start tag, attempts to find the ProfileMgrWebImpl bean and * and determine if the banner option is on.  If the profilemgr bean exists * and the banner option is on, the body is processed.  A method is also * provided for inner tags (i.e. BannerImgTag) to retrieve the banner string. * All accesses to the profileMgr bean happen in this tag.  If it is not found * a Jsp exception is not thrown.  Rather, the body is just not included. * * The banner tag might be used like this, assuming the tag library is * identified with "j2ee", and the profilemgr bean is initialized and present * in the jsp page: * * <j2ee:banner> *  <img src="<%=request.getContextPath()%>/<j2ee:bannerImg />"> * </j2ee:banner> */public class BannerTag extends TagSupport {  private ProfileMgrWebImpl profileMgrBean;  public int doStartTag() {    profileMgrBean =      (ProfileMgrWebImpl) pageContext.findAttribute("profilemgr");    if (profileMgrBean == null) return(SKIP_BODY);    ExplicitInformation eInfo = profileMgrBean.getExplicitInformation();    if (!eInfo.getBannerOpt()) return(SKIP_BODY);    else return(EVAL_BODY_INCLUDE);  }  public String getBannerString() {    //return(profileMgrBean.getBanner());    return "BannerTag not used";  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?