JSP自定义标签之Hello Costom tag小例子
1、项目结构

2、实现自定义tag所需依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
3、HelloTag.java
package com.tag; import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException; /**
* Created by Administrator on 2016/7/11.
*/
public class HelloTag extends SimpleTagSupport { @Override
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
out.println("Hello Custom Tag!");
}
}
4、costom.tld
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>Example TLD</short-name>
<tag>
<name>Hello</name>
<tag-class>com.tag.HelloTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
5、index.jsp
<%@ taglib prefix="ex" uri="../WEB-INF/custom.tld"%>
<html>
<body>
<h2>Hello World!</h2>
<form action="test1" method="post" id="form1">
<input type="submit" name="submit" value="button">
</form>
<ex:Hello></ex:Hello>
</body>
</html>
注:这里需要引入标签库
<%@ taglib prefix="ex" uri="../WEB-INF/custom.tld"%>
6、结果

JSP自定义标签之Hello Costom tag小例子的更多相关文章
- 一个简单的jsp自定义标签
学到了一个简单的jsp自定义标签,后面有更多的例子,会更新出来: 例子1: 步骤: 1.编写标签实现类: 继承javax.servlet.jsp.tagext.SimpleTagSupport; 重写 ...
- 【转】Jsp自定义标签详解
一.前言 原本是打算研究EXtremeComponents这个jsp标签插件,因为这个是自定义的标签,且自身对jsp的自定义标签并不是非常熟悉,所以就打算继续进行扫盲,开始学习并且整理Jsp自定义标签 ...
- 自定义标签报 无法为TAG [my2:hello]加载标记处理程序类[null]
今天练习jsp自定义标签的时候,等我写好全部和检查万无一失的时候.执行然后报错了 无法为TAG [my2:hello]加载标记处理程序类[null] 我反复检查代码,发现代码也没什么问题.后面通过百度 ...
- JSP 自定义标签
0 标签技术的API继承体系 1 作用 jsp自定义标签用于移除页面中的java代码 2 实现 2.1 标签处理类ViewIPTag.java package com.zsm.util; import ...
- JSP自定义标签开发入门
一般情况下开发jsp自定义标签需要引用以下两个包 import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; 首先我们需要大致了解开发 ...
- jsp自定义标签分析
jsp自定义标签的优势体现在于jsp页面上面减少了java代码. jsp自定义标签有三大部分组成,首先是类继承TagSupport,实现doStartTag方法. public int doStart ...
- JSP自定义标签库
总所周知,JSP自定义标签库,主要是为了去掉JSP页面中的JAVA语句 此处以格式化输出时间戳为指定日期格式为例,简单介绍下JSP自定义标签的过程. 编写标签处理类(可继承自javax.servlet ...
- jsp 自定义标签解决jsp页面中int时间戳的时间格式化问题
jsp 自定义标签解决jsp页面中int时间戳的时间格式化问题 之前在项目中根据需求,需要自定义标签,经过查询w3c文档,自己也踩了一些坑,特此记录自定义标签的步骤,下面就以我之前的一个例子中的定义一 ...
- java JSP自定义标签
来至: http://blog.csdn.net/jiangwei0910410003/article/details/23915373 http://blog.csdn.net/jiangwei09 ...
随机推荐
- 伪集群zookeeper模式下codis的部署安装
1,zookeeper伪集群部署 部署在192.168.0.210服务器上 下载 去官网将3.4.6版本的zookeeper下载下来到/app目录下解压 首先 ...
- MVC JsonResult的用法
本文导读:当客户端调用某个Action方法并希望以JSON的格式返回请求的数据时,ASP.NET MVC需要有一种机制将CLR对象转换成JSON格式予以响应,而这可以通过JsonResult来解决.下 ...
- redhat安装VMware tools的方法
如果我们仔细看的话, 就会发现在VMware软件界面的左下角处显示着 "you don't have VMware Tools installed",即我们还没安装VMware T ...
- Java 生成验证码图片
生成验证码图片并对提交的输入进行验证 // HttpServletResponse常见应用——生成验证码 // 利用BufferedImage类生产随机图片 public static final i ...
- 11 Clever Methods of Overfitting and how to avoid them
11 Clever Methods of Overfitting and how to avoid them Overfitting is the bane of Data Science in th ...
- MyEclipse 中各种 libraries 的含义
MyEclipse 中各种 libraries 的含义 JRE System Library,Java EE 5 Libraries,Referenced Libraries这三个都是各 ...
- Joomla![1.5-3.4.5]反序列化远程代码执行EXP(直接写shell)
Usage:x.py http://xxx.com # coding=utf-8# author:KuuKi# Help: joomla 1.5-3.4.5 unserialize remote co ...
- jQuery里$(this)和this的区别在哪?
$(this)是jquery对象,能调用jquery的方法,例如click(), keyup().而this,则是html元素对象,能调用元素属性,例如this.id,this.value.例如假设已 ...
- Reachability(判断网络是否连接)
类似于一个网络状况的探针. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabili ...
- 最万能的解决mysql数据库的各种问题的办法
ubuntu下安装mysql及卸载mysql方法 1. 删除mysql a. sudo apt-get autoremove --purge mysql-server-5.0 b. sudo apt- ...