天天看點

tag标簽檔案

tag檔案隻是以tag為字尾名的文本檔案。除了jsp頁面指令外,其他JSP元素都可以出現在tag檔案中

頁面引用格式

<%@ taglib prefix="ui" tagdir="/WEB-INF/tags" %>

tagdir:用于指定tag檔案目錄,當頁面使用<ui:xxxx>進,會查找該目錄下對應的xxxx.tag檔案。

prefix:指定使用時标簽字首

使用格式

<ui:xxxx></ui:xxxx>

例子:

<%@ taglib prefix="sys" tagdir="/WEB-INF/tags/sys" %>

<%@ taglib prefix="act" tagdir="/WEB-INF/tags/act" %>

tag标簽檔案

tag檔案添加屬性:當tag檔案需要引用頁面傳入參數時,就需要在tag檔案中填加屬性

定義屬性格式

<%@ attribute name="attributename" required="true" type="com.myapp.util.ListPage" %>

name(必須):屬性名

required(必須):指定是否必須傳

type(可選):指定屬性類型。

tag檔案獲得傳入參數值

String attributename=(String) pageContext.getAttribute("attributename");

或者在jsp元素中使用${pageScope.attributename}

也可使用<jsp:doBody/> 擷取引用頁面标簽内的body内容。

例:

<%@ attribute name="replace" type="java.lang.String" required="true" description="需要替換的textarea編号"%>

<%@ attribute name="uploadPath" type="java.lang.String" required="false" description="檔案上傳路徑,路徑後自動添加年份。若不指定,則編輯器不可上傳檔案"%>

引用的頁面:

<sys:ckeditor replace="projectIntroduction" uploadPath="/jy/basicOfficeGeng" />