package com.pr.tag;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
public class IPTag implements Tag {
private HttpServletRequest request;
private HttpServletResponse response;
private JspWriter out;
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
return 0;
}
public int doStartTag() throws JspException {
// TODO Auto-generated method stub
try {
out.println(request.getRemoteAddr());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
public Tag getParent() {
// TODO Auto-generated method stub
return null;
}
public void release() {
// TODO Auto-generated method stub
}
public void setPageContext(PageContext arg0) {
// TODO Auto-generated method stub
request = (HttpServletRequest) arg0.getRequest();
response = (HttpServletResponse) arg0.getResponse();
out = arg0.getOut();
}
public void setParent(Tag arg0) {
// TODO Auto-generated method stub
}
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/ipshow.tld" prefix="ip" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<ip:ip/>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>ip</short-name>
<tag>
<name>ip</name>
<tag-class>com.pr.tag.IPTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>