夢(mèng)幻之旅

          DEBUG - 天道酬勤

             :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評(píng)論 :: 0 Trackbacks
          java:
          package com.rwclp.usermanager.util;

          import java.io.IOException;

          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.jsp.JspException;
          import javax.servlet.jsp.JspWriter;
          import javax.servlet.jsp.tagext.BodyContent;
          import javax.servlet.jsp.tagext.BodyTagSupport;

          import com.framework.commons.util.StrUtil;
          import com.rwclp.global.util.UserSessionDTO;

          /**
           * <ul>
           * <li>Title:[UserRightTag]</li>
           * <li>Description: [用戶(hù)權(quán)限JSP標(biāo)簽]</li>
           * <li>All right reserved.</li>
           * <li>Created by [Huyvanpull] [2010-8-18]</li>
           * <li>Midified by [修改人] [修改時(shí)間]</li>
           * </ul>
           * 
           * 
          @version 1.0
           
          */

          @SuppressWarnings(
          "serial")
          public class UserRightTag extends BodyTagSupport
          {
              
          /** 標(biāo)簽體內(nèi)容 */
              
          private BodyContent bodyContent;
              
              
          /** 權(quán)限名稱(chēng) */
              
          private String name = "";
              
              
          public int doEndTag() throws JspException
              
          {
                  
          // 獲取JSPWriter對(duì)象
                  JspWriter out = bodyContent.getEnclosingWriter();
                  
          try
                  
          {
                      String content 
          = bodyContent.getString();
                      
          // 判斷標(biāo)簽體是否有值和權(quán)限名是否有值
                      if (StrUtil.noVal(content))
                      
          {
                          content 
          = "標(biāo)簽體為空";
                          out.write(content);
                          
          return EVAL_PAGE;
                      }

                      
                      
          // 判斷權(quán)限名是否為空
                      if (StrUtil.noVal(name))
                      
          {
                          content 
          = "權(quán)限名為空";
                          out.write(content);
                          
          return EVAL_PAGE;
                      }

                      
                      HttpServletRequest request 
          = null;
                      request 
          = (HttpServletRequest) pageContext.getRequest();
                      UserSessionDTO userSessionDTO 
          = UserSessionDTO.get(request);
                      
                      
          // 判斷用戶(hù)是否登陸
                      if (userSessionDTO == null)
                      
          {
                          content 
          = "用戶(hù)沒(méi)有登陸";
                          out.write(content);
                          
          return EVAL_PAGE;
                      }

                      
                      
          // 得到權(quán)限值
                      if (userSessionDTO.getRightByName(name).equals("0"))
                      
          {
                          out.write(content);
                      }

                  }

                  
          catch (IOException e)
                  
          {
                      e.printStackTrace();
                  }

                  
          return EVAL_PAGE;
              }

              
              
          public void setBodyContent(BodyContent bodyContent)
              
          {
                  
          this.bodyContent = bodyContent;
              }

              
              
          public void setName(String name)
              
          {
                  
          this.name = name;
              }

          }

          xml:
          <?xml version="1.0" encoding="GBK"?>
          <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation
          ="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
              version
          ="2.0">
              
          <tlib-version>1.0</tlib-version>
              
          <short-name>mytaglib</short-name>
              
          <uri>http://www.crazyit.org/mytaglib</uri>
              
          <tag>
                  
          <name>right</name>
                  
          <tag-class> com.rwclp.usermanager.util.UserRightTag</tag-class>
                  
          <body-content>JSP</body-content>
                  
          <attribute>  
                      
          <name>name</name>  
                      
          <required>true</required>  
                      
          <rtexprvalue>true</rtexprvalue>  
                  
          </attribute>  
              
          </tag>
          </taglib>
          jsp:
          <%@taglib uri="/WEB-INF/myTag.tld" prefix="myTag" %>
          <myTag:right name="addUserRight">
          是否可能顯示
          </myTag:right>
          posted on 2010-08-18 14:05 HUIKK 閱讀(195) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Java
          主站蜘蛛池模板: 井冈山市| 布尔津县| 扶沟县| 富源县| 道孚县| 东海县| 沅江市| 班玛县| 高安市| 惠来县| 革吉县| 曲水县| 北辰区| 台中县| 苗栗县| 崇左市| 电白县| 四平市| 延安市| 新泰市| 扎鲁特旗| 石楼县| 恩平市| 正定县| 陆川县| 政和县| 隆子县| 乌兰察布市| 饶阳县| 邵阳县| 蒙自县| 麻阳| 海门市| 富民县| 墨江| 平泉县| 阳原县| 灯塔市| 巴彦县| 泰来县| 务川|