JSTL基础 SimpleTagSupport 自定义标签 标签体empty

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSTL基础 SimpleTagSupport 自定义标签 标签体empty相关的知识,希望对你有一定的参考价值。

礼悟:
     好好学习合思考,尊师重道存感恩。叶见寻根三返一,江河湖海同一体。
          虚怀若谷良心主,愿行无悔给最苦。读书锻炼强身心,诚劝且行且珍惜。




       javaEE:7           
       javaSE:1.8
          JSTL:1.2.2  
      server:tomcat 8.5
    browser:Chrome/Firefox
             os:windows7 x64
            ide:MyEclipse 2017

 

项目结构

技术分享图片

 


jizuiku-tags.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/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
  version="2.0">
  
  <tlib-version>1.0</tlib-version>
  <short-name>jzk</short-name>
  <uri>http://www.jizuiku.com/tags/1.0</uri>
  
    
  <!-- 配置标签 -->
  <tag>
  	<name>sayHelloWoldFromMySimpleTagSupport</name><!-- 指定当前标签的名称 -->
  	<tag-class>com.jizuiku.tag.MySimpleTagSupport</tag-class><!-- 当前标签的处理类 -->
  	<body-content>empty</body-content><!-- 指定标签体的类型 empty空标签 -->
  </tag>
  
</taglib>

 

MySimpleTagSupport.java

package com.jizuiku.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * SimpleTagSupport 实现了 SimpleTag接口
 * 将tomcat传来的礼物都保存了起来
 * 
 * @author 博客园-给最苦 
 * @version V2017.12.04
 */
public class MySimpleTagSupport extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {
		// 看看 getJspContext 方法返回的是什么? 
		this.getJspContext().getOut().print("HelloWoldFromMySimpleTagSupport");
		
	}

}

 

MyJsp.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="j" uri="/WEB-INF/tlds/jizuiku-tags.tld"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP ‘MyJsp.jsp‘ starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
	<j:sayHelloWoldFromMySimpleTagSupport/>
  </body>
</html>

 

浏览器查看

技术分享图片

 

 


学习资源:itcast和itheima视频库。如果您有公开的资源,可以分享给我的话,用您的资源学习也可以。
博文是观看视频后,融入思考写成的。博文好,是老师讲得好。博文坏,是 给最苦 没认真。















以上是关于JSTL基础 SimpleTagSupport 自定义标签 标签体empty的主要内容,如果未能解决你的问题,请参考以下文章

JSTL基础 SimpleTagSupport 自定义标签 标签体scriptless

jstl标签基础开发步骤

自己封装JSTL 自定义标签

简单实用jstl实现“登录|注册”

JSTL基础 SimpleTag 自定义标签 标签体empty

Web基础了解版08-JSTL