Íê³ÉÄãµÄ×Ô¶¨Òå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
Ïà¹ØÎĵµ£º
1.½ûÖ¹¿Í»§¶Ë»º´æÒªÔÚ<head>ÖмÓÈëÀàËÆÈçÏÂÄÚÈÝ£º
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
2.ÔÚ·þÎñÆ÷µÄ¶¯Ì¬ÍøÒ³ÖнûÖ¹»º´æ£¬Òª¼ÓÈëÀàË ......
1¡¢jspÒ³ÃæÂÒÂ룺
ÔÚjspÒ³Ãæ¿ªÊ¼Ìí¼Ó<%pageEncoding="uft-8"%>
2¡¢servletÊä³öÂÒÂ룺
ÔÚÊä³öÄÚÈÝ֮ǰ£¬ÏÈÖ´ÐÐresponse.setContentType
("text/html;charset=utf-8")
3¡¢ÔÚformÀïÓÃpost·½Ê½Ìá½»²ÎÊý£º
1£©½ÓÊÕʱ¼Órequest.setCharacterEncoding("utf-8")
2£©Ê¹ÓùýÂËÆ÷£¬ÔÚ½ÓÊÕ²ÎÊý֮ǰ£¬É趨´«µÝµÄ²ÎÊýÄ ......
Ê×ÏÈÊÇÌá½»Ò³Ãæ£ºÈý¸ö±íµ¥(form1,form2,form3)
<form name="form1" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="3">
&nb ......
ÓõÄÊÇMySqlÊý¾Ý¿â£¬ÀïÃæÓÐÊý¾Ý¿âµÄ½Å²½£¬ÔËÐÐbbs.sqlÎļþ¾Í¿ÉÒÔÁË¡£
ÓõÄMVCģʽ£¬ÓÃjsp ×öÏÔÊ¾Ò³Ãæ£¬ÓÃservlet×ö¿ØÖƲ㣬ÓÃJavaBean×öÄ£ÐͲã
ÏÂÔØµØÖ·£º
http://www.800disk.com/ContentPane.aspx?down=ok&filepath=lcbjava%2fMybbs.rar
°ÑÉÏÃæµÄµØÖ·¸´ÖƵ½ä¯ÀÀÆ÷¾Í¿ÉÒÔÏÂÔØ ......
ÔÚjspÖУ¬Èç¹ûÔÚurlÖд«µÝÖÐÎÄʱ»á³öÏÖÂÒÂ룬ÔÚÍøÉϹØÓÚÕâÒ»ÎÊÌâµÄ½â¾ö·½·¨Î廨°ËÃÅ£¬µ«¶¼²»ÊǺÜ×àЧ£¡Æäʵ½â¾ö·½·¨·Ç³£¼òµ¥£º µÚÒ»²½£º±àÂ루ÒÔ´«µÝµÄ²ÎÊýΪstrΪÀý£© ÔÚ´«µÝÊý¾Ýǰ½«str½øÐбàÂëJava.net.URLEncoder.encode(str) µÚ¶þ²½£º½âÂë ÔÚ»ñÈ¡Êý¾Ý¶Ë½«µÃµ½µÄÊý¾Ý½øÐнâÂë new String£¨str.getBytes("ISO8859_1")£©
......