Jsp tag 可以灵活的将公共JSP代码模块化,相似<jsp:include page="./include.jsp"></jsp:include>等等。jsp
咱们本身定义的JSP模块代码可能在引用时会依据不一样的引用场景,需要显示的内容略有不一样,这时使用JSP.INCLUDE就不能知足咱们的需求了。模块化
所以,咱们可以使用JSP tag 的方式实现。ui
第一步this
在WEB-INF/tags文件夹下建立 demo.tag 文件spa
代码例如如下:class
<%@tag pageEncoding="UTF-8" isELIgnored="false" body-content="empty"%>test
<!-- 定义引用时必要的属性 (可选)-->require
<%@ attribute name="type" required="true" rtexprvalue="true" %>coding
this jsp tag content type:<%=this.type %>引用
第二步 使用该TAG
咱们仅仅需要在使用的JSP 头部引入该Tag
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
其次在需要输出TAG信息的地方使用
<tags:demo type="test"/>
完毕。