1、编写一个实现Tag接口的Java类(标签处理器类)

  1. package me.gacl.web.tag;
  2.  
  3. import java.io.IOException;
  4.  
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.jsp.JspException;
  7. import javax.servlet.jsp.JspWriter;
  8. import javax.servlet.jsp.PageContext;
  9. import javax.servlet.jsp.tagext.Tag;
  10.  
  11. public class ViewIPTag implements Tag {
  12.  
  13. //接收传递进来的PageContext对象
  14. private PageContext pageContext;
  15.  
  16. @Override
  17. public int doEndTag() throws JspException {
  18. System.out.println("调用doEndTag()方法");
  19. return 0;
  20. }
  21.  
  22. @Override
  23. public int doStartTag() throws JspException {
  24. System.out.println("调用doStartTag()方法");
  25. HttpServletRequest request =(HttpServletRequest) pageContext.getRequest();
  26. JspWriter out = pageContext.getOut();
  27. String ip = request.getRemoteAddr();
  28. try {
  29. //这里输出的时候会抛出IOException异常
  30. out.write(ip);
  31. } catch (IOException e) {
  32. //捕获IOException异常后继续抛出
  33. throw new RuntimeException(e);
  34. }
  35. return 0;
  36. }
  37.  
  38. @Override
  39. public Tag getParent() {
  40. return null;
  41. }
  42.  
  43. @Override
  44. public void release() {
  45. System.out.println("调用release()方法");
  46. }
  47.  
  48. @Override
  49. public void setPageContext(PageContext pageContext) {
  50. System.out.println("setPageContext(PageContext pageContext)");
  51. this.pageContext = pageContext;
  52. }
  53.  
  54. @Override
  55. public void setParent(Tag arg0) {
  56.  
  57. }
  58.  
  59. }

2、在WEB-INF/目录下新建tld文件,在tld文件中对标签处理器类进行描述

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMwAAAB/CAIAAAAsHrp+AAAMxUlEQVR4nO2d20/cVhrAz//A0z6stEJVVlEeUlLgwU9ouw/Z12oVStsoUh68F6KkYbW7SdskRRmmlJbibUnKJYEkkMDCQGkmuM1uaBoRVFapCEmzKYt3wqXTgblmMlzGw8CefTgzHttjmyHj07Hh++kTso+Px4P80zln7O/YCAMAZVChvwCw/QHJAOqAZAB1QDKAOiAZQB2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tqb/LsT1or2t6YEPG8UY92K6J3uxVtiksqkxA5JZGoQ+cs9OLa5/58MtLX8zjskfsQXjOx+eWlwHySwMQl9MBIfuhYXAhs5VVquHENgYugeZsVYGoURyw30v0DD0pOCJ1M8XDUNP3PcCIJmFKfg8NpgSlx879N8GfkpAMoA6tpTsNl+vGYX+XoA2tpTs1nCDPAmbxKPrfzDbMxrPxMt+OPL2x5aS3bz+YbZk0yPv/Ntkz0Ayc7ClZMNDTWJinUQ8kRQT6/HE+ux40/TIO4+u/54f+sik44Bk5mBLyYYGPiY5/rv3V1fXtq7E16trW3fvr14R11fF9euDH5t0HJDMHGwpWf/fzy+tJpdW15wt/bv3V8dWk7v3Vztb+pdWk0uryYH+c5p78WzqXTeKZ6lnSjNP809X2+Qp//JnzKY/kWcRw/EcI9VP7y07NEhmB672tJKs6+jyGtFr9/7q6DLJyV7r7W3R3CvTLvEswzDkrKcdkxmYqbj5U/5Tu6lMlT5a2lt+bJDMFnR2XSBZ1+FYqjFztvSHY6mc7Cvd7dq7pc80zzKcwLMMJ2CBY9KOKWE4IbcHsJM9JUHlsmoug2Q2oe3SJZJ1HYgmpJYsEE1l+ndc6dTZjygl04vnVA1aVn2QzARsKdm5i90k65rotRARiWqksKXjit6OAscwTKYvlDpNVV/Is4ZP+c+8yTDlTlZB+mNAMoyxTSXj2nq8IfHHUIL8uvSGEuTXpTcsekNi84WrunvKtZGpIW1SDvB1nvKf3pFnpSZM+lyQTANbStb4aR/Jup4LiPNBcT4Qnw/G5wLiXDA+FxCbWnsL/QUBBbaUrP68a8YfJzHrj8/64zN+UVr98Hxfob8goMCWkjmbB52fDNZ9MuhsHqxrJn8/I4XOTwbfb3YV+gsCCmwpGWAvQDKAOiAZQB2QDKAOSAZQByQDqPN/nz5HfW30QdYAAAAASUVORK5CYII=" alt="" />

  gacl.tld文件的代码如下:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2.  
  3. <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
  6. version="2.0">
  7. <!-- description用来添加对taglib(标签库)的描述 -->
  8. <description>孤傲苍狼开发的自定义标签库</description>
  9. <!--taglib(标签库)的版本号 -->
  10. <tlib-version>1.0</tlib-version>
  11. <short-name>GaclTagLibrary</short-name>
  12. <!--
  13. 为自定义标签库设置一个uri,uri以/开头,/后面的内容随便写,如这里的/gacl ,
  14. 在Jsp页面中引用标签库时,需要通过uri找到标签库
  15. 在Jsp页面中就要这样引入标签库:<%@taglib uri="/gacl" prefix="gacl"%>
  16. -->
  17. <uri>/gacl</uri>
  18.  
  19. <!--一个taglib(标签库)中包含多个自定义标签,每一个自定义标签使用一个tag标记来描述 -->
  20. <!-- 一个tag标记对应一个自定义标签 -->
  21. <tag>
  22. <description>这个标签的作用是用来输出客户端的IP地址</description>
  23. <!--
  24. 为标签处理器类配一个标签名,在Jsp页面中使用标签时是通过标签名来找到要调用的标签处理器类的
  25. 通过viewIP就能找到对应的me.gacl.web.tag.ViewIPTag类
  26. -->
  27. <name>viewIP</name>
  28. <!-- 标签对应的处理器类-->
  29. <tag-class>me.gacl.web.tag.ViewIPTag</tag-class>
  30. <body-content>empty</body-content>
  31. </tag>
  32.  
  33. </taglib>

2.2、在Jsp页面中使用自定义标签

  1、使用"<%@taglib uri="标签库的uri"  prefix="标签的使用前缀"%>"指令引入要使用的标签库。

例如:在jspTag_Test1.jsp中引用gacl标签库

  1. <%@ page language="java" pageEncoding="UTF-8"%>
  2. <!-- 使用taglib指令引用gacl标签库,标签库的前缀(prefix)可以随便设置,如这里设置成 prefix="xdp" -->
  3. <%@taglib uri="/gacl" prefix="xdp"%>
  4. <!DOCTYPE HTML>
  5. <html>
  6. <head>
  7. <title>输出客户端的IP</title>
  8. </head>
  9.  
  10. <body>
  11. 你的IP地址是(使用java代码获取输出):
  12. <%
  13. //在jsp页面中使用java代码获取客户端IP地址
  14. String ip = request.getRemoteAddr();
  15. out.write(ip);
  16. %>
  17. <hr/>
  18. 你的IP地址是(使用自定义标签获取输出):
  19. <%--使用自定义标签viewIP --%>
  20. <xdp:viewIP/>
  21. </body>
  22. </html>

 标签的运行效果如下:

  

  从运行效果种可以看到,使用自定义标签就可以将jsp页面上的java代码移除掉,如需要在jsp页面上输出客户端的IP地址时,使用 <xdp:viewIP/>标签就可以代替jsp页面上的这些代码:

  1. <%
  2. 2 //在jsp页面中使用java代码获取客户端IP地址
  3. 3 String ip = request.getRemoteAddr();
  4. 4 out.write(ip);
  5. 5 %>

JSP引擎遇到自定义标签时,首先创建标签处理器类的实例对象,然后按照JSP规范定义的通信规则依次调用它的方法。
    1、public void setPageContext(PageContext pc), JSP引擎实例化标签处理器后,将调用setPageContext方法将JSP页面的pageContext对象传递给标签处理器,标签处理器以后可以通过这个pageContext对象与JSP页面进行通信。
    2、public void setParent(Tag t),setPageContext方法执行完后,WEB容器接着调用的setParent方法将当前标签的父标签传递给当前标签处理器,如果当前标签没有父标签,则传递给setParent方法的参数值为null。
    3、public int doStartTag(),调用了setPageContext方法和setParent方法之后,WEB容器执行到自定义标签的开始标记时,就会调用标签处理器的doStartTag方法。
    4、public int doEndTag(),WEB容器执行完自定义标签的标签体后,就会接着去执行自定义标签的结束标记,此时,WEB容器会去调用标签处理器的doEndTag方法。
    5、public void release(),通常WEB容器执行完自定义标签后,标签处理器会驻留在内存中,为其它请求服务器,直至停止web应用时,web容器才会调用release方法。

  我们在tomcat服务器的"work\Catalina\localhost\JavaWeb_JspTag_study_20140816\org\apache\jsp"目录下可以找到将jspTag_Test1.jsp翻译成Servlet后的java源代码,如下图所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlQAAABjCAIAAADSGglCAAAa8UlEQVR4nO2dW28bxxXH6Rj5RLIa8COkXyAfICWKPOi5RoG8pIDYlxIqjNR9cQg4gdukUlyVEbyW5Tg14ri1H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BNM6UzdUzBJ+eWEQUP6V6ul0lTCY1GHpiqCFun471M5o+8VP2/Yj91dztC+EGLNMltR/i9+RF9/4PncaT9u0Heze/2732n50rd7b/+c3WxtebCdyeSY+Ng839OIVkGbr8hhbiN2mSmFCTN7NASrJ/JPhQc2U/xO/7ZvvE6XOmFxM/65NGss/QjUpRMbTIThOrUXUQ4d0uFscfuhwfKgfxmzDQvmmBOh9N7rpJ1wCM7If4zb/5tv2ltBo3RWdVJuI+PDxW30gHxxq6+LLpgPgBMII4H8fUrew1AAMTFz8wa0D8AAAHnzzFb3uvm0eXwHQD8QMAHHy297rlj3MKZuvceNru9CcVdh5MCb4PAAAADiztTt+58fTvX8kB1VOLH154+a93T9/ECy+88Dqwr9/95dbKl49anV4O4gcAAAAcAiB+AAAAZg6IHwAAgJkD4gcAAGDmgPgBAACYOSB+AAAAZg6IHwAAgJnj//OPMEHjvYwBAAAAAElFTkSuQmCC" alt="" />

  打开jspTag_005fTest1_jsp.java文件,可以看到setPageContext(PageContext pc)、setParent(Tag t)、doStartTag()、doEndTag()、release()这5个方法的调用顺序和过程。

  1. package org.apache.jsp;
  2.  
  3. import javax.servlet.*;
  4. import javax.servlet.http.*;
  5. import javax.servlet.jsp.*;
  6.  
  7. public final class jspTag_005fTest1_jsp extends org.apache.jasper.runtime.HttpJspBase
  8. implements org.apache.jasper.runtime.JspSourceDependent {
  9.  
  10. private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
  11.  
  12. private static java.util.List _jspx_dependants;
  13.  
  14. static {
  15. _jspx_dependants = new java.util.ArrayList(1);
  16. _jspx_dependants.add("/WEB-INF/gacl.tld");
  17. }
  18.  
  19. private org.apache.jasper.runtime.TagHandlerPool _005fjspx_005ftagPool_005fxdp_005fviewIP_005fnobody;
  20.  
  21. private javax.el.ExpressionFactory _el_expressionfactory;
  22. private org.apache.AnnotationProcessor _jsp_annotationprocessor;
  23.  
  24. public Object getDependants() {
  25. return _jspx_dependants;
  26. }
  27.  
  28. public void _jspInit() {
  29. _005fjspx_005ftagPool_005fxdp_005fviewIP_005fnobody = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
  30. _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
  31. _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  32. }
  33.  
  34. public void _jspDestroy() {
  35. _005fjspx_005ftagPool_005fxdp_005fviewIP_005fnobody.release();
  36. }
  37.  
  38. public void _jspService(HttpServletRequest request, HttpServletResponse response)
  39. throws java.io.IOException, ServletException {
  40.  
  41. PageContext pageContext = null;
  42. HttpSession session = null;
  43. ServletContext application = null;
  44. ServletConfig config = null;
  45. JspWriter out = null;
  46. Object page = this;
  47. JspWriter _jspx_out = null;
  48. PageContext _jspx_page_context = null;
  49.  
  50. try {
  51. response.setContentType("text/html;charset=UTF-8");
  52. pageContext = _jspxFactory.getPageContext(this, request, response,
  53. null, true, 8192, true);
  54. _jspx_page_context = pageContext;
  55. application = pageContext.getServletContext();
  56. config = pageContext.getServletConfig();
  57. session = pageContext.getSession();
  58. out = pageContext.getOut();
  59. _jspx_out = out;
  60.  
  61. out.write("\r\n");
  62. out.write("<!-- 引用gacl标签库,标签库的前缀(prefix)可以随便设置,如这里设置成 prefix=\"gacl\" -->\r\n");
  63. out.write("\r\n");
  64. out.write("<!DOCTYPE HTML>\r\n");
  65. out.write("<html>\r\n");
  66. out.write(" <head>\r\n");
  67. out.write(" <title>输出客户端的IP</title>\r\n");
  68. out.write(" </head>\r\n");
  69. out.write(" \r\n");
  70. out.write(" <body>\r\n");
  71. out.write(" 你的IP地址是(使用java代码获取输出):\r\n");
  72. out.write(" ");
  73.  
  74. //在jsp页面中使用java代码获取客户端IP地址
  75. String ip = request.getRemoteAddr();
  76. out.write(ip);
  77.  
  78. out.write("\r\n");
  79. out.write(" <hr/>\r\n");
  80. out.write(" 你的IP地址是(使用自定义标签获取输出):");
  81. if (_jspx_meth_xdp_005fviewIP_005f0(_jspx_page_context))
  82. return;
  83. out.write("\r\n");
  84. out.write(" </body>\r\n");
  85. out.write("</html>\r\n");
  86. } catch (Throwable t) {
  87. if (!(t instanceof SkipPageException)){
  88. out = _jspx_out;
  89. if (out != null && out.getBufferSize() != 0)
  90. try { out.clearBuffer(); } catch (java.io.IOException e) {}
  91. if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
  92. }
  93. } finally {
  94. _jspxFactory.releasePageContext(_jspx_page_context);
  95. }
  96. }
  97.  
  98. private boolean _jspx_meth_xdp_005fviewIP_005f0(PageContext _jspx_page_context)
  99. throws Throwable {
  100. PageContext pageContext = _jspx_page_context;
  101. JspWriter out = _jspx_page_context.getOut();
  102. // xdp:viewIP
  103. me.gacl.web.tag.ViewIPTag _jspx_th_xdp_005fviewIP_005f0 = (me.gacl.web.tag.ViewIPTag) _005fjspx_005ftagPool_005fxdp_005fviewIP_005fnobody.get(me.gacl.web.tag.ViewIPTag.class);
  104. _jspx_th_xdp_005fviewIP_005f0.setPageContext(_jspx_page_context);
  105. _jspx_th_xdp_005fviewIP_005f0.setParent(null);
  106. int _jspx_eval_xdp_005fviewIP_005f0 = _jspx_th_xdp_005fviewIP_005f0.doStartTag();
  107. if (_jspx_th_xdp_005fviewIP_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
  108. _005fjspx_005ftagPool_005fxdp_005fviewIP_005fnobody.reuse(_jspx_th_xdp_005fviewIP_005f0);
  109. return true;
  110. }
  111. _005fjspx_005ftagPool_005fxdp_005fviewIP_005fnobody.reuse(_jspx_th_xdp_005fviewIP_005f0);
  112. return false;
  113. }
  114. }

   下面重点分析一下上述代码中标红色的那个 private boolean _jspx_meth_xdp_005fviewIP_005f0(PageContext _jspx_page_context)方法中的代码

  ①、这里是实例化一个viewIP标签处理器类me.gacl.web.tag.ViewIPTag的对象

  1. 1 // xdp:viewIP
  2. 2 me.gacl.web.tag.ViewIPTag _jspx_th_xdp_005fviewIP_005f0 = (me.gacl.web.tag.ViewIPTag) _005fjspx_005ftagPool_005fxdp_005fviewIP_005fnobody.get(me.gacl.web.tag.ViewIPTag.class);

  ②、实例化标签处理器后,调用setPageContext方法将JSP页面的pageContext对象传递给标签处理器

  1. 1 _jspx_th_xdp_005fviewIP_005f0.setPageContext(_jspx_page_context);

  ③、setPageContext方法执行完后,接着调用的setParent方法将当前标签的父标签传递给当前标签处理器,如果当前标签没有父标签,则传递给setParent方法的参数值为null

  1. 1 _jspx_th_xdp_005fviewIP_005f0.setParent(null);

  ④、调用了setPageContext方法和setParent方法之后,WEB容器执行到自定义标签的开始标记时,就会调用标签处理器的doStartTag方法

  1. 1 int _jspx_eval_xdp_005fviewIP_005f0 = _jspx_th_xdp_005fviewIP_005f0.doStartTag();

  ⑤、WEB容器执行完自定义标签的标签体后,就会接着去执行自定义标签的结束标记,此时,WEB容器会去调用标签处理器的doEndTag方法

  1. 1 if (_jspx_th_xdp_005fviewIP_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE)

  这就是自定义标签的执行流程。

Web学习之自定义标签的更多相关文章

  1. javaweb学习6——自定义标签

    声明:本文只是自学过程中,记录自己不会的知识点的摘要,如果想详细学习JavaWeb,请到孤傲苍狼博客学习,JavaWeb学习点此跳转 本文链接:https://www.cnblogs.com/xdp- ...

  2. Spring 源码学习(1) —— 自定义标签

    Spring 工作流程是先加载解析xml配置文件:配置文件中存在默认的标签,也可以自定义标签.解析默认标签调用: private void parseDefaultElement(Element el ...

  3. java web 学习笔记 - JSP标签编程

    1.JSP标签编程简介 标签编程在开发中并不常见,主要是为了更好的理解struts等框架的标签而打基础,完善相关知识体系. 标签编程分为: 一个继承自TagSupport的标签类,一个在WEB-INF ...

  4. Angular 学习笔记——自定义标签

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  5. JavaWeb学习篇之----自定义标签&&JSTL标签库详解

    今天来看一下自定义标签的内容,自定义标签是JavaWeb的一部分非常重要的核心功能,我们之前就说过,JSP规范说的很清楚,就是Jsp页面中禁止编写一行Java代码,就是最好不要有Java脚本片段,下面 ...

  6. JSP自定义标签——传统标签

    同JSP标签一样,自定义标签主要用于移除JSP页面中的Java代码,可以看到我们在JSP中其实是禁止使用Java脚本的,任何要想通过Java代码实现的功能都必须以标签形式来处理,可以使用JSP标签,J ...

  7. JSP自定义标签就是如此简单

    tags: JSP 为什么要用到简单标签? 上一篇博客中我已经讲解了传统标签,想要开发自定义标签,大多数情况下都要重写doStartTag(),doAfterBody()和doEndTag()方法,并 ...

  8. 一、JSP标签介绍,自定义标签

    一.JSP标签介绍 1. 标签库有什么作用 自定义标签库是一种优秀的表现层技术,之前介绍的MVC模式,我们使用jsp作为表现层,但是jsp语法嵌套在html页面,美工还是很难直接参与开发,并且jsp脚 ...

  9. Jsp2.0自定义标签(第二天)——自定义循环标签

    今天是学习自定义标签的第二天,主要是写一个自定义的循环标签. 先看效果图: 前台页面Jsp代码 <%@ page language="java" contentType=&q ...

随机推荐

  1. android插件化-apkplugdemo源代码阅读指南-10

    阅读本节内容前可先了解 apkplug基础教程 本教程是基于apkplug V1.6.8 版本号编写  最新开发方式以官网为准 可下载最新的apkplugdemo源代码http://git.oschi ...

  2. C++ - Vector 计算 均值(mean) 和 方差(variance)

    Vector 计算 均值(mean) 和 方差(variance) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24623187 ...

  3. asp.net 前台js和后台得到FormView中的控件,以TextBox为例

    一.前台js获取FormView中的控件 js得到前端控件的ID,比如TextBox(这里设置其ID为TextBox1),大家都知道,是document.getElementById("&l ...

  4. 从零开始Unity3D游戏开发【4 材质球和渲染纹理】

    [创建材质球] 1.Project 面板下  create-Material 然后将材质球拖放到物体,物体的颜色便会和材质球相同: [渲染纹理 RenderTexture]

  5. 权威指南之脚本化jquery

    jqury函数 jquery()($())有4种不同的调用方式 第一种是最常用的调用方式是传递css选择器(字符串)给$()方法.当通过这种方式调用时,$()方法会返回当前文档中匹配该选择器的元素集. ...

  6. GridView中日期显示格式

    DataFormatString="{0:d}"

  7. android入门——UI(4)

    GridView控件实现菜单 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...

  8. SSIS: Lookup组件高级用法,生成推断成员(inferred member)

    将数据导入事实表如果无法匹配维度表的记录一般有两种处理方式. 一是将不匹配记录输出到一个表中待后续处理,然后重新导入.二是先生成维度Key,后续再完善维度key,本文指导各位使用第二种方式. 背景 比 ...

  9. jsp建立错误页自动跳转

    在各个常用的web站点中,经常会发现这样一个功能:当一个页面出错后,会自动跳转到一个页面上进行错误信息的提示. 想要完成错误页的操作,则一定要满足两个条件: 1.指定错误出现时的跳转页,通过error ...

  10. C#根据文件流判断文件类型

    判断文件真实的类型,不是通过扩展名来判断: /// <summary> /// 判断文件格式 /// http://www.cnblogs.com/babycool /// </su ...