/*實現功能:自己來定義一個標籤,用於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>