jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.cgmcc.com/jsp/mytag" prefix="my" %>
<%@ taglib uri="http://www.cgmcc.com/jsp/mytag2" prefix="my2" %>
<%
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 'comparedata.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>
<!-- 实现一个输球 两个数值 1和2 输出最大值 -->
<my2:maxVal num2="123" num1="889"/>
</body>
</html>
java
package com.cgm.tldtest;
import java.io.IOException;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.JspTag;
import javax.servlet.jsp.tagext.SimpleTag;
public class MyMaxVal implements SimpleTag {
private PageContext pageContext;
private Integer num1;
private Integer num2;
public Integer getNum1() {
return num1;
}
public void setNum1(Integer num1) {
this.num1 = num1;
}
public Integer getNum2() {
return num2;
}
public void setNum2(Integer num2) {
this.num2 = num2;
}
public void doTag() throws JspException, IOException {
if (num1>num2) {
pageContext.getOut().print(num1+"大于"+num2);
}else{
pageContext.getOut().print(num1+"小于或者等译"+num2);
}
}
public JspTag getParent() {
return null;
}
public void setJspBody(JspFragment jspBody) {
}
public void setJspContext(JspContext pc) {
this.pageContext=(PageContext) pc;
}
public void setParent(JspTag parent) {
}
}
tld
<?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">
<tlib-version>1.3</tlib-version>
<short-name>my3</short-name>
<uri>http://www.cgmcc.com/jsp/readfile</uri>
<tag>
<name>readFile</name>
<tag-class>com.cgm.readFile.TagReadFile</tag-class>
<body-content>empty</body-content>
<attribute>
<name>file</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
</taglib>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.cgmcc.com/jsp/mytag" prefix="my" %>
<%@ taglib uri="http://www.cgmcc.com/jsp/mytag2" prefix="my2" %>
<%
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 'comparedata.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>
<!-- 实现一个输球 两个数值 1和2 输出最大值 -->
<my2:maxVal num2="123" num1="889"/>
</body>
</html>
java
package com.cgm.tldtest;
import java.io.IOException;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.JspTag;
import javax.servlet.jsp.tagext.SimpleTag;
public class MyMaxVal implements SimpleTag {
private PageContext pageContext;
private Integer num1;
private Integer num2;
public Integer getNum1() {
return num1;
}
public void setNum1(Integer num1) {
this.num1 = num1;
}
public Integer getNum2() {
return num2;
}
public void setNum2(Integer num2) {
this.num2 = num2;
}
public void doTag() throws JspException, IOException {
if (num1>num2) {
pageContext.getOut().print(num1+"大于"+num2);
}else{
pageContext.getOut().print(num1+"小于或者等译"+num2);
}
}
public JspTag getParent() {
return null;
}
public void setJspBody(JspFragment jspBody) {
}
public void setJspContext(JspContext pc) {
this.pageContext=(PageContext) pc;
}
public void setParent(JspTag parent) {
}
}
tld
<?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">
<tlib-version>1.3</tlib-version>
<short-name>my3</short-name>
<uri>http://www.cgmcc.com/jsp/readfile</uri>
<tag>
<name>readFile</name>
<tag-class>com.cgm.readFile.TagReadFile</tag-class>
<body-content>empty</body-content>
<attribute>
<name>file</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
</taglib>