最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于JSP 自定義標簽使用實例介紹

 更新時間:2013年04月18日 12:02:48   作者:  
本篇文章小編為大家介紹,基于JSP 自定義標簽使用實例介紹,需要的朋友參考下

添加JSP自定義標簽:

先添加一個tld文件到WEB-INF文件夾中
<?xml version="1.0" encoding="UTF-8" ?>
<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">

<description>myTag</description>
<display-name>JSTL core</display-name>
<tlib-version>1.0</tlib-version>
<short-name>cnweb</short-name>
<uri>http://www.cnweb.cn</uri>

<tag><!-- 一個tag標簽對應(yīng)一個自定義tag標簽類 -->
<description>MyTag</description>
<name>when</name>
<tag-class>cn.example.when</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>test</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
引用規(guī)則:
<%@ taglib uri="http://www.cnweb.cn" prefix="cnweb"%>

 定義錯誤處理頁面:

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/errors/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/errors/error1.jsp</location>
</error-page>

自定義標簽執(zhí)行流程:

SimpleTagSupport

/* Jsp引擎遇到簡單類,實例化該類;
* 調(diào)用setJspContext,把頁面pageContext傳遞給標簽處理類;
* 調(diào)用setParent把父標傳遞進去,如果沒有,傳遞null
* 調(diào)用setJspBody方法,把封裝了標簽體JspFragment傳遞給標簽處理器類
* 執(zhí)行頁面中的自定義標簽,doTag()方法;-->執(zhí)行完成,銷毀對象
*/

JspFragment jf = this.getJspBody();
jf.invoke(this.getJspContext().getOut());//如果不顯示則不進行處理

--------------------------------------------------------------------

public class tagShowOrNot extends TagSupport {
public int doStartTag() throws JspException {
return Tag.EVAL_BODY_INCLUDE;//顯示body
//return Tag.SKIP_BODY;//隱藏body
//Tag.EVAL_PAGE;//顯示page
//Tag.SKIP_PAGE;//隱藏page
}} 

TagSupport
/*編寫一個實現(xiàn)TagSupport的類;
*在tld文件中對標簽處理器類進行描述(tld文件的位置:WEB-INF下)
*在jsp頁面中導(dǎo)入和使用標簽
*
*jsp執(zhí)行過程中遇到自定義標簽時,先實例化該類;
*然后執(zhí)行方法:setPageContext()-->setParent()-->doStartTag()
*如果有標簽體,一般會執(zhí)行標簽體;doEndTag()-->整個標簽執(zhí)行完后一般會執(zhí)行:release()
*
*控制整個jsp頁面是否執(zhí)行;
*控制jsp頁面某一部分內(nèi)容是否執(zhí)行;
*控制jsp頁面內(nèi)容重復(fù)執(zhí)行;
*修改jsp頁面內(nèi)容輸出;
*/

//該方法在執(zhí)行標簽體后,執(zhí)行doEndTag()方法之前執(zhí)行,直到該方法返回IterationTag.SKIP_BODY;
public int doAfterBody() throws JspException {
time--;
System.out.println("重復(fù)" + time);
if (time > 0) {
return IterationTag.EVAL_BODY_AGAIN;
} else
return IterationTag.SKIP_BODY;
}

相關(guān)文章

最新評論

德庆县| 习水县| 平泉县| 会宁县| 辽中县| 惠安县| 九江县| 江安县| 荔浦县| 东城区| 麟游县| 华宁县| 玉溪市| 德保县| 宜昌市| 桦南县| 河北区| 吐鲁番市| 垦利县| 从江县| 岳阳县| 昂仁县| 红桥区| 南华县| 襄樊市| 垣曲县| 米林县| 六安市| 东至县| 高雄市| 武山县| 沾化县| 遂昌县| 康乐县| 湄潭县| 勃利县| 清水县| 伊金霍洛旗| 北京市| 胶州市| 铜梁县|