ViewIPTag.java
public class ViewIPTag extends TagSupport {
public int doStartTag() throws JspException {
String ip = pageContext.getRequest().getRemoteAddr();
try {
pageContext.getOut().write(ip);
} catch (Exception e) {
e.printStackTrace();
}
return super.doStartTag();
}
}
xu.tld
<?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>
<jsp-version>1.0</jsp-version>
<tlib-version>1.0</tlib-version>
<short-name>wangtongtaglib</short-name>
<uri>/wangtongtaglib</uri>
<tag>
<name>viewip</name>
<tag-class>tag.ViewIPTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://csdn.hbsi.3g/TagTest" prefix="wangtong" %>
<%
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 'index.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>
<wangtong:viewip />
</body>
</html>
用自定义标签实现HTML中的特殊元素转义字符
最新推荐文章于 2023-09-11 22:28:45 发布