Íê³ÉÄãµÄ×Ô¶¨ÒåJSP Tag±êÇ©£Basic Coustom Tag
˵Ã÷£º»ùÓÚEclipse 3.2 + Tomcat 4.0±àÒëÍê³É
1.Íê³ÉÄã×Ô¼ºµÄTag Class£¬javax.servlet.jspÖÐÌṩһ¸öTag½Ó¿ÚÀà
TagSupport ºÍ BodyTagSupportÁ½¸öÀ࣬Äã×Ô¼ºµÄTag Class±ØÐë
extendsÆäÖÐÒ»¸ö¡£±¾ÀýÖÐHrefTag Class extends TagSupportÀ࣬²¢
Íê³ÉÁËdoStratTag·½·¨µÄÖØÐ´£¬Ö÷Òª´úÂëÈçÏ£º
public int doStartTag(){
JspWriter ōut = pageContext.getOut();
String value = getValue();
String code = getCode();
System.out.println("value = " + value);
System.out.println("code = " + code);
try{
if(code != null && value != null) {
out.print("<a href=");
out.print("'");
out.print(value);
out.print("'");
out.print(">");
out.print(code);
out.print("</a>");
}
}catch(IOException e){
System.out.println("Error in Tag:" + e.getMessage());
}
return(SKIP_BODY);
}
¶ÔÓÚÒ»¸öTag ClassÀ´Ëµ£¬ÏëÒªÕýÈ·µÄ¹¤×÷£¬±ØÐèÓÐÏàÓ¦µÄTLDÎļþ£¬±¾ÀýΪ
test-taglib.tld£¬¶¨ÒåÈçÏ£º
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tag>
<name>href</name>
<tagclass>com.test.tag.HrefTag</tagclass>
<bodycontent>jsp</bodycontent>
<info>Simplest example: href the page </info>
<attribute>
<name>code</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
&nbs
Ïà¹ØÎĵµ£º
JSPÊý¾Ý¿âÁ¬½Ó´óÈ«
2008-07-22 11:47
Ò»¡¢jspÁ¬½ÓOracle8/8i/9iÊý¾Ý¿â£¨ÓÃthinģʽ£©
testoracle.jspÈçÏ£º
< %@ page contentType="text/html;charset=gb2312"% >
< %@ page import="java.sql.*"% >
< html >
< body >
< %Class.forName("oracle.jdbc.driver.OracleDriver").new ......
1¡¢jspÒ³ÃæÂÒÂ룺
ÔÚjspÒ³Ãæ¿ªÊ¼Ìí¼Ó<%pageEncoding="uft-8"%>
2¡¢servletÊä³öÂÒÂ룺
ÔÚÊä³öÄÚÈÝ֮ǰ£¬ÏÈÖ´ÐÐresponse.setContentType
("text/html;charset=utf-8")
3¡¢ÔÚformÀïÓÃpost·½Ê½Ìá½»²ÎÊý£º
1£©½ÓÊÕʱ¼Órequest.setCharacterEncoding("utf-8")
2£©Ê¹ÓùýÂËÆ÷£¬ÔÚ½ÓÊÕ²ÎÊý֮ǰ£¬É趨´«µÝµÄ²ÎÊýÄ ......
µÚÒ»ÖÖ JavaScriptÁ¬½ÓÊý¾Ý¿â£º
<mce:script language="JavaScript"><!--
// ´´½¨Êý¾Ý¿â¶ÔÏó
var objdbConn = new ActiveXObject("ADODB.Connection");
// DSN×Ö·û´®
var strdsn = "Driver={SQL Server};SERVER=192.168.0.210;UID=xhb;PWD=xhb;DATABASE=books";
// ´ò¿ªÊý¾ÝÔ´
objdbConn.Open(strdsn);
// ......
µÚÒ»²½£ºJDKÓëTomcatµÈµÄÏÂÔØÓëÅäÖÃ
×îеÄJDKΪ6.0£¨jdk-6u12-windows-i586-p.exe£©£¬tomcatΪ6.0(apache-tomcat-6.0.18.exe)
¿ª·¢»·¾³£º
JDK: jdk-6u12-windows-i586-p.exe
ÏÂÔØµØÖ·:http://java.sun.com/javase/downloads/index.jsp
Tomcat:apache-tomcat-6.0.18.exe
ÏÂÔØµØÖ·:http://tomcat.a ......