自定义jsp标签入门
来源:互联网 发布:js post方式下载文件 编辑:程序博客网 时间:2024/04/30 20:00
java代码
package com.itcast.zdyJsp;import java.io.IOException;import javax.management.RuntimeErrorException;import javax.servlet.http.HttpServletRequest;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.tagext.TagSupport;public class ShowIPTag extends TagSupport {/** * */private static final long serialVersionUID = 1L;/** * 开始标签 * 1.自定义标签的作用:消除jsp中的java脚本 * 二:编写步骤: * 1.编写一个类 实现 Tag 接口 (一般继承 TagSupport) * 覆盖掉对应的方法: * * 注:可以通过pageContext对象获取其他8打对象的引用 * 3.在WEB-INF 中扩展名为tld的xml文件 */@Overridepublic int doStartTag() throws JspException {HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();String ip = request.getRemoteAddr();JspWriter out = pageContext.getOut();try {out.print(ip);} catch (IOException e) {throw new RuntimeException(e);}return super.doStartTag();}}
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"> <description>HEIMA1.0 core library</description> <display-name>HEIMA core</display-name> <tlib-version>1.0</tlib-version> <short-name>itheima</short-name> <uri>http://java.itheima.com/jsp/core</uri><tag> <description> show client ip </description> <name>showIp</name> <tag-class>com.itcast.zdyJsp.ShowIPTag</tag-class> <body-content>empty</body-content> </tag></taglib>
jsp页面
<?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"> <description>HEIMA1.0 core library</description><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="http://java.itheima.com/jsp/core" prefix="itheima" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>My JSP 'zdyJspdemo.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> This is my JSP page. <br> <itheima:showIp/> </body></html>
http://java.itheima.com/jsp/core</uri><tag> <description> show client ip </description> <name>showIp</name> <tag-class>com.itcast.zdyJsp.ShowIPTag</tag-class> <body-content>empty</body-content> </tag></taglib>
0 0
- 自定义jsp标签入门
- JSP自定义标签入门
- JSP自定义标签入门实例
- jsp自定义标签入门例子
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- JSP自定义标签开发入门
- php基础知识
- 调试中的心理因素
- 二分搜索
- 深度优先搜索
- 【hadoop之翊】——hadoop配置ssh免密码登录,解决ssh设置好了依然需要输入密码的问题
- 自定义jsp标签入门
- day_2 servlet 三种开发方法
- C++primer学习笔记(1)
- ADB server didn't ACK 是怎么回事?安卓虚拟机无法安装App
- visual studio 2010 创建的MFC ActiveX 控件的工程 不能运行 提示:无法启动.ocx程序
- c# 在WinForm 窗体间传递信息(转换为VB.net)
- 圆的表面积和体积
- ConcurrentHashMap之实现细节
- spring jdbctemplate事务配置