jsp×Ô¶¨Òå±êÇ©(tag)¿ª·¢
1 ±ê¼Ç´¦Àí³ÌÐòÀà
´¦ÀíÀà¼Ì³ÐTagSupportÀà²¢ÖØÔØdoStartTag()·½·¨,
Ôڸ÷½·¨ÖÐʹÓÃout.print();Êä³öÐèÒªµÄÊý¾Ýµ½Ê¹Óñ¾±êÇ©µÄjspÒ³Ãæ
package cn.xxx;
public class DateTag extends TagSupport {
private static final long serialVersionUID = 1L;
public int doStartTag() throws javax.servlet.jsp.JspException {
JspWriter out;
try {
out = pageContext.getOut();
out.print("helloÄãºÃ" + new Date());
} catch (IOException ioe) {
throw new JspException("I/O Error : " + ioe.getMessage());
}
return Tag.SKIP_BODY;//return 0;
}
}
2 ´´½¨Ê¹ÓñêÇ©ÀàµÄ´´TLDÎļþ
(¿ÉÒÔ´ÓstrutsÖеıêÇ©¿âÖеÄ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
web-jsptaglibrary_2_0.xsd" verson="2.0">
<tlib-version>1.0</tlib-version>
<jspversion>1.1</jspversion>
<info>A simple tag library</info>
<tag>
<name>displayDate</name>
<tagclass>cn.eecn.DateTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Display Date</info>
</tag>
</taglib>
3 µ¼Èë±êÇ©¿â
* ·½·¨1
ÔÚweb.xmlÎļþÖÐÏȾ²Ì¬µ¼ÈëtldÎļþ,ÔÙjspÖÐÓñðÃûµ¼Èë±êÇ©
web.xml:
<taglib>
<taglib-uri>myTags</taglib-uri>
<taglib-location>/WEB-INF/lib/DateTagLib.tld</taglib-location>
</taglib>
jsp:
<%@ taglib uri="myTags" prefix="abc" %>
* ·½·¨2:
ÔÚjspÒ³ÃæÖÐÖ±½ÓʹÓö¯Ì¬µ¼ÈëtldÎļþ
<%@ taglib uri="/WEB-INF/lib/DateTagLib.tld" prefix="abc" %>
4 ÔÚÒ³ÃæÖÐʹÓñêÇ©
jsp
<abc:displayDate />
ÒýÓòο¼:http://blog.myspace.cn/e/406226695.htm
Ïà¹ØÎĵµ£º
±í½á¹¹£º
CREATE TABLE `article` (
`id` int(10) unsigned ......
(1)include ÔÚJSP±àÒë³ÉJavaÀàÎļþʱ£¬ÏȽ«includeÎļþÄÚÈݺϲ¢ºó£¬ÔÙ½øÐбàÒë
(2)jsp:include ÔËÐÐʱºÏ²¢,»á½«ÔËÐÐʱµÄ½á¹û°üº¬½øÀ´
(3)c:import ÔËÐÐʱºÏ²¢,»á½«ÔËÐÐʱµÄ½á¹û°üº¬½øÀ´
Òò´Ë£¬
£¨1£©ÀûÓÃinclude°üº¬µÄÒ³ÃæÖÐÈç¹û°üº¬Á˺ÍÔÒ ......
//ÔËÐÐͼ:
//Á¬½Ó×Ö·û´®
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName(driverName).newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
//ÿҳÏÔʾ¼Ç¼Êý
int PageSize ......
Ò»¡¢ÏÈ¿´¿´ÈçºÎÈ¡µ±Ç°Ê±¼ä²¢ÏÔʾµÄ´úÂ룺
------------------------------------------------
<%
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date currentTime = new java.util.Date();//µÃµ½µ±Ç°ÏµÍ³Ê±¼ä
String str_date1 = formatter.form ......