为了简化,标签的开发,所以标签文件的出现就是为此而来!!
(一)
1。定义一个简单的标签文件:nowTime.tag
<jsp:useBean id="nowTime" class="java.util.Date"/>
${nowTime}
注意,这个,标签文件必须放到WEB-INF/tags下,或者,WEB-INF/tags的子目录下
2。在jsp页面中可以直接调用:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="myTag" tagdir="/WEB-INF/tags"%>
注意:这里,只能用tagdir,不能用uri,并且要注意路径
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<myTag:nowTime></myTag:nowTime>
</body>
</html>
(二)
1。定义一个简单的标签文件:nowTime.tag
<jsp:useBean id="nowTime" class="java.util.Date"/>
${nowTime}
注意,这个,标签文件必须放到WEB-INF/tags下,或者,WEB-INF/tags的子目录下
2。在标签描述文件中定义,该文件标签
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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.0</tlib-version>
<uri>/test-1.0</uri>
<tag-file>
<name>nowTime</name>
<path>/WEB-INF/tags/nowTime.tag</path>
</tag-file>
注意:这里,定义,标签的,路径,该标签文件一定要放到WEB-INF/tags下,或者,WEB-INF/tags的子目录下
</taglib>
3。jsp中调用
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="myTag" uri="/test-1.0"%>
注意:这里与上面一的不同,这里,因为,在标签描述文件里配置了,所以这里可用uri
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<myTag:nowTime></myTag:nowTime>
</body>
</html>