自訂標籤流程,標籤流程
1.建立java類,繼承TagSupport類
2.覆蓋doStartTag()方法,在該方法中編寫jsp頁面中的java代碼
3.ServletRequest request = this.pageContext.getRequest(); //獲得request對象
JspWriter out = this.pageContext.getOut();//獲得輸出資料流
4.在WEB-INF目錄下建立tld檔案:
<?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/j2eehttp://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>SimpleTagLibrary</short-name>
<uri>http:www.test.com</uri><tag>
<name>viewIP</name>
<tag-class>aaaaa.viewIPTag</tag-class>
<body-content>empty</body-content></tag>
<function>
<description>Converts the string to all caps</description>
<name>caps</name>
<function-class>jsp2.examples.el.Functions</function-class>
<function-signature>java.lang.String caps( java.lang.String )</function-signature>
</function>
</taglib></taglib>
5.編輯<uri></uri>內容
6.在頁面中引入標籤。