为JSP自定义你自己的标签吧

来源:互联网 发布:淘宝客服在家上班 编辑:程序博客网 时间:2024/06/07 18:38
/*实现功能:自己来定义一个标签,用于jsp中日期:20130930作者:烟大阳仔*/1.编写一个实现tag接口的JAVA类public int doStartTag() throws JspException {HttpServletRequest request=(HttpServletRequest)this.pageContext.getRequest();JspWriter out=this.pageContext.getOut();String ip=request.getRemoteAddr();try {out.print(ip);} catch (IOException e) {throw new RuntimeException(e);}return super.doStartTag();}2.在tld文件中对标签处理器进行描述(tld文件的位置WEB-INF里面)<?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>A tag library exercising SimpleTag handlers.</description>    <tlib-version>1.0</tlib-version>    <short-name>TagLib</short-name>    <uri>/TagLib</uri>    <tag>        <name>VeiwIP</name>        <tag-class>cn.com.web.tag.TagLibIP</tag-class>        <body-content>empty</body-content>    </tag></taglib>3.在jsp页面中使用标签<body>     你的IP地址是:<TagLib:VeiwIP/>  </body>

原创粉丝点击