JSP TAG

Jsp tag 能够灵活的将公共JSP代码模块化,类似<jsp:include page="./include.jsp"></jsp:include>等等。

我们自己定义的JSP模块代码可能在引用时会依据不同的引用场景,须要显示的内容略有不同,这时使用JSP.INCLUDE就不能满足我们的需求了。

因此,我们能够使用JSP tag 的方式实现。

第一步

在WEB-INF/tags文件夹下创建 demo.tag 文件

代码例如以下:

<%@tag pageEncoding="UTF-8" isELIgnored="false" body-content="empty"%>

<!--  定义引用时必要的属性 (可选)-->

<%@ attribute name="type" required="true" rtexprvalue="true" %>

this jsp tag content type:<%=this.type %>


第二步  使用该TAG

我们仅仅须要在使用的JSP 头部引入该Tag 

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

其次在须要输出TAG信息的地方使用

<tags:demo type="test"/>


完毕。



posted @ 2015-05-11 10:31  lcchuguo  阅读(313)  评论(0编辑  收藏  举报