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
Ïà¹ØÎĵµ£º
//ÔËÐÐͼ:
//Á¬½Ó×Ö·û´®
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 ......
ÉÏһƪ·ÖÒ³ÎÄÕ£¬ÊÇÓÃÓÚmysql£¬ÉÔ΢ÐÞ¸ÄÏ£¬ÓÃÓÚSqlserver2005/2008£¬Ã»ÓÐÒì³£´¦Àí¡£Ã»Óп¼ÂÇÐÔÄܵȡ£
ÏÖ½«´úÂëÌù³ö£¬ÒÔ¹©³õѧÕ߲ο¼£º
×¢£ºÑûÔÂʹÓû·¾³Eclipse 3.4.2+Tomcat 6.18+Sqlserver2005 sp3µ÷ÊԳɹ¦¡£
Ò³ÃæpagelistDemo.jspÄÚÈÝ£º
Code
<%@ page language="java" contentType="text/html; ......
JspµÄ¾ÅÖÖ¶ÔÏóÎÒ¼òÊöÖ®£º
page
application
request
response
session
config
out
pageContext
page
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
response
<%
response.setHeader("Pragma","No-cache");
respons ......
JSPÖеÄÌø×ª£º
(1). forward()·½·¨
ʹÓõ½javax.servlet.RequestDispatcherÀà
RequestDispatcher rd = getServletContext().getRequestDispatcher("url");
rd.forward(requestVar,requestVar); //´«µÝservletµÄÈë¿Ú²ÎÊý
/*forwardº¯ÊýÒѾ°ÑÔÒ³ÃæµÄrequest,response¶ÔÏó´«ÈëеÄÒ³Ãæ£¬Òò´ËÕâо ......
J2EE ̽Ë÷Õß:
´´½¨ºÍ¹ÜÀíÓÐ״̬ Web Ó¦ÓóÌÐò
¶Ô4ÖֻỰ×÷ÓÃÓòµÄÊʵ±´¦Àí
ÎĵµÑ¡Ïî
½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ
ÍØÕ¹ Tomcat Ó¦ÓÃ
......