奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

java語言

Java自定義簡單標簽實例

時間:2024-10-19 15:42:48 java語言 我要投稿
  • 相關推薦

Java自定義簡單標簽實例

  引導語:當jsp的內置標簽和jstl標簽庫內的標簽都滿足不了需求,這時候就需要開發者自定義標簽。以下是百分網小編分享給大家的Java自定義簡單標簽實例,歡迎閱讀!

  下面將以權限的控制為例自定義一個標簽:

  一、標簽類型

  步驟:

  1.自定義一個類PerssionTag 繼承SimpleTagSupport(自定義標簽一般都會繼承這個類)

  package cn.com.liveuc.privilege.tag;

  import java.io.IOException;

  import java.util.ArrayList;

  import java.util.List;

  import java.util.Set;

  import javax.servlet.jsp.JspException;

  import javax.servlet.jsp.PageContext;

  import javax.servlet.jsp.tagext.SimpleTagSupport;

  import cn.com.liveuc.privilege.model.Privilege;

  import cn.com.liveuc.privilege.model.Resource;

  import cn.com.liveuc.privilege.model.Role;

  import cn.com.liveuc.privilege.model.User;

  /**

  *

  * @說明 自定義標簽

  */

  public class PerssionTag extends SimpleTagSupport {

  //自定義標簽屬性,用于標簽傳入參數

  private String uri;

  //接收標簽傳入的參數

  public void setUri(String uri) {

  this.uri = uri;

  }

  @Override

  public void doTag() throws JspException, IOException {

  //獲取用戶登陸后保存的Session

  PageContext page = (PageContext) this.getJspContext();

  User user = (User) page.getSession().getAttribute("login");

  //如果用戶登陸

  if(user != null) {

  //用戶登陸判斷用戶權限

  List list = new ArrayList();

  //獲取用戶的角色

  Set role = user.getRole();

  for(Role r:role) {

  //獲取角色對應的權限

  Set privilege = r.getPrivilege();

  for(Privilege p:privilege) {

  //獲取權限對應的資源

  Set res = p.getResource();

  for(Resource re:res) {

  list.add(re.getUri());

  }

  }

  }

  for(String ur:list) {

  //判斷用戶的權限

  if(ur.equals(uri)) {

  this.getJspBody().invoke(null); //有權限輸出標簽體內容

  }

  }

  }

  }

  }

  2.在WEB-INF下創建tld文件描述標簽。

  復制代碼 代碼如下:

  version="2.0"

  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">

  the Apache Struts framework includes a library of custom tags.

  The tags interact with the framework's validation and internationalization features;

  to ensure that input is correct and output is localized.

  The Struts Tags can be used with JSP FreeMarker or Velocity."]]>

  "Struts Tags"

  2.2.3

  s

  /wxt

  per

  cn.com.liveuc.privilege.tag.PerssionTag

  scriptless

  uri

  true

  true

  3.運用標簽

  在Jsp頁面導入標簽:

  %@taglib prefix="wxt" uri="/wxt" %

  運用標簽:

  用戶管理

  用戶權限包含uri資源的將會輸出標簽內容。

【Java自定義簡單標簽實例】相關文章:

java調用c函數的實例09-16

Java自定義范型的應用技巧10-16

Java隊列類編寫實例09-05

java讀取解析xml文件實例08-05

Java中的多態用法實例分析10-23

Java的Struts框架中標簽的使用方法07-29

java中通用的線程池實例代碼08-27

Java 異步回調機制實例解析08-22

java多線程同步塊實例講解素材08-28

有關Java開發中常用到For循環的實例05-31

主站蜘蛛池模板: 连州市| 石棉县| 崇州市| 潮安县| 宜阳县| 镇巴县| 龙井市| 邢台县| 宁都县| 西充县| 宣恩县| 丁青县| 交口县| 寻乌县| 连州市| 临武县| 冕宁县| 景洪市| 三江| 高淳县| 娄底市| 武隆县| 扎囊县| 和静县| 黄大仙区| 庆城县| 石河子市| 彰化县| 玉田县| 定州市| 南涧| 东乡| 曲麻莱县| 略阳县| 壤塘县| 渝中区| 江达县| 尉氏县| 灌南县| 大同县| 沙雅县|