jsp自定义标签
来源:互联网 发布:夏茗悠扒皮知乎 编辑:程序博客网 时间:2024/06/05 10:16
一:编写类
package cn.web.tag;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
@SuppressWarnings("serial")
public class ViewIpTag extends TagSupport{
public int doEndTag() throws JspException{
JspWriter out=this.pageContext.getOut();
HttpServletRequest request=(HttpServletRequest) this.pageContext.getRequest();
String ip=request.getLocalAddr();
try {
out.print(ip);
} catch (IOException e) {
throw new RuntimeException(e);
}
return super.doStartTag();
}
}
二:文件(注意:此文件应该放在WEB-INF目录下)
package cn.web.tag;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
@SuppressWarnings("serial")
public class ViewIpTag extends TagSupport{
public int doEndTag() throws JspException{
JspWriter out=this.pageContext.getOut();
HttpServletRequest request=(HttpServletRequest) this.pageContext.getRequest();
String ip=request.getLocalAddr();
try {
out.print(ip);
} catch (IOException e) {
throw new RuntimeException(e);
}
return super.doStartTag();
}
}
三:编写jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://www.clyao.cn" prefix="clyao" %>
<%
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 'tag.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">
</head>
<body>
您德 ip是:<clyao:viewIP/>
</body>
</html>
四:到此,恭喜您已经配好一个自定义标签。。。。
- JSP----自定义标签---简单标签
- jsp自定义标签-----嵌套标签
- JSP标签编程----自定义标签
- JSP 自定义标签:简单标签
- JSP标签-JSTL-自定义标签
- JSP自定义标签-Select标签
- jsp 自定义标签---标签文件
- JSP自定义标签
- JSP自定义标签学习心得
- JSP自定义标签试验
- JSP 自定义标签库
- 自定义JSP标签
- 创建JSP自定义标签
- 关于自定义标签 jsp
- 关于自定义标签 jsp
- jsp 自定义分页标签
- JSP自定义标签简介
- JSP自定义标签例子
- java.lang.IllegalStateException The specified child already has a parent. You must call removeView()
- OpenCV中cvcontours上的所有点集合
- Allowed memory size of xxx bytes
- 常用资源备忘
- 关于Struts 标签:datetimepicker
- jsp自定义标签
- 虚拟机linux里上网nat
- 对于 EntityDataSource,必须为每个 Parameter 指定 Type 或 DbType (但不能同时指定)
- 优雅使用ubuntu指南
- js校验(wallet)
- 静态路由配置
- 黑马程序员_学习Oracle总结
- stm32f4基于spi用fatfs读写SD卡的实现
- 修改ubuntu默认配色方案