spring自定義標籤接口類RequestContextAwareTag,該類位於org.springframework.web.servlet.tags.RequestContextAwareTagjava
package com.experian.web.tag; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import org.springframework.web.servlet.tags.RequestContextAwareTag; import com.billionsfinance.collectsm.common.utils.CollectionSecurityUtils; public class CollectionSecurity extends RequestContextAwareTag { private static final long serialVersionUID = 1L; private String content; public String getContent() { return content; } public void setContent(String content) { this.content = content; } @Override protected int doStartTagInternal() throws Exception { try { JspWriter out = this.pageContext.getOut(); String value = CollectionSecurityUtils.decryptMode(this.content); showdict(value, out); } catch (Exception e) { e.printStackTrace(); } return SKIP_BODY; } private void showdict(String value, JspWriter out) { try { out.print(value); } catch (IOException e) { e.printStackTrace(); } } @Override public int doEndTag() throws JspException { return EVAL_PAGE; } }
content屬性爲頁面輸入值。
在新建的tld標籤庫文件中進行業務處理類進行處理
<?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" 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"> <tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <short-name>exp</short-name> <uri>/experian</uri> <tag> <name>CollectionSecurity</name> <tag-class>com.experian.web.tag.CollectionSecurity</tag-class> <body-content>empty</body-content> <attribute> <name>content</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
標籤說明:
標籤說明 | |
標籤名 |
標籤說明 |
tlib-version: |
tab標籤版本號 |
jsp-version |
jsp版本號 |
name | 定義屬性的名稱。每一個標籤的是屬性名稱必須是惟一的。 |
required | 指定屬性是不是必須的或者可選的,若是設置爲false爲可選。 |
rtexprvalue | 聲明在運行表達式時,標籤屬性是否有效。 |
type | 定義該屬性的Java類類型 。默認指定爲 String |
description | 描述信息 |
fragment | 若是聲明瞭該屬性,屬性值將被視爲一個 JspFragment。 |
tag-class |
tag業務處理類地址 |
jsp文件中聲明操做
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %> <!--使用-->
<exp:CollectionSecurity content="${item.idNo}"/>