JSP×Ô¶¨Òå±êÇ©ÓÉdzµ½ÉîÏêϸ½²½â(3)
¾Å¡¢ÈçºÎ´´½¨°üº¬JSPÍøÒ³¾²Ì¬Îı¾µÄÎļþ£º
1.ʹÓÃjava.util.PropertiesÀàÀ´´æ·ÅÒªÌæ»»ÍøÒ³ÖÐ×Ô¶¨ÒåJSP±êÇ©µÄ¾²Ì¬Îı¾
2.PropertiesÀà´ú±íÁËһϵÁÐÊôÐԵļ¯ºÏ£¬ÆäʵÀý¼È¿ÉÒÔ±»±£´æµ½Á÷ÖУ¬Ò²¿ÉÒÔ´ÓÁ÷ÖмÓÔØ¡£ÕâЩÎı¾ÒÔkey/valueµÄÐÎʽ´æ·ÅÔÚWEB-INFĿ¼Ï£¬ÀýÈçkey=value£¬ÔÚÊôÐÔÁбíÖÐÕâЩkey/value¶¼ÊÇStringÀàÐ͵Ä
Ê®¡¢PropertiesÀàµÄ³£ÓÃAPI£º
1.setProperty(String key, String value)£ºµ÷ÓÃHashtableÀàµÄput·½·¨Ìí¼ÓÊôÐÔ
2.getProperty(String key)£º»ñÈ¡ÊôÐÔÁбíÖÐkey¶ÔÓ¦µÄÊôÐÔÖµ
3.load(InputStream in)£º´ÓÊäÈëÁ÷¶ÔÏóInputStreamÖжÁÈ¡ÊôÐÔÁбí(Properties list)
4.store(OutputStream out,String coMMent)£ºÊ¹ÓÃÊʵ±µÄ¸ñʽ½«ÊôÐÔÁбíµÄÊôÐÔ¶ÔдÈëÊä³öÁ÷¶ÔÏóÖУ¬Ä¬ÈÏʹÓÃISO-88590-1±àÂë¸ñʽ,ÒÔÐеķ½Ê½´¦ÀíÊäÈë¡£ÊôÐ﵀ key/valueÖ®¼äÒÔ¡±=¡¢:¡±Åä¶Ô£¬ÒԻسµ¡¢»»Ðзָôkey/valueÅä¶Ô
ʮһ¡¢ServletContextÀàµÄ³£ÓÃAPI£º
1.getContext(String uripath)£º·µ»Ø·þÎñÆ÷ÖÐuripathËù´ú±íµÄServletContext¶ÔÏó
2.getInitParameter(String name)£º·µ»ØServletConfig¶ÔÏóÖÐname²ÎÊýµÄÖµ
3.getMineType(String file)£º·µ»Øfile²ÎÊý´ú±íµÄÎļþµÄMIMEÀàÐÍ
4.getRequestDispatcher(String path)£º·µ»Øpath´ú±íµÄRequestDispacher¶ÔÏó
5.getResourceAsStream(String path)£ºÒÔÊäÈëÁ÷µÄÐÎʽ·µ»Øpath¶ÔÓ¦µÄ×ÊÔ´£¬ÔÚÊäÈëÁôÖжÔÏó¿ÉÒÔΪÈÎÒâÐÎʽµÄÊý¾Ý£¬path²ÎÊý±ØÐëÒÔ¡°/¡±¿ªÊ¼ÇÒÏà¶ÔÓÚContext Root
Ê®¶þ¡¢ÈçºÎʹÓÃServletContxt¶ÁÈ¡²¢±£´æÊôÐÔÎļþ£º
1.´´½¨java.util.PropertiesÀà¶ÔÏó
2.»ñÈ¡ServletContext¶ÔÏó
3.½«ÊôÐÔÎļþÒÔÊäÈëÁ÷µÄÐÎʽ¶ÁÈ뵽ij¸öÊäÈëÁ÷¶ÔÏóÖÐ
4.½«ÊäÈëÁ÷¶ÔÏó¼ÓÔص½Properties¶ÔÏóÖÐ
5.½«Properties¶ÔÏó±£´æµ½ServletContext¶ÔÏóÖÐ
Ê®Èý¡¢ÈçºÎÔÚWebÓ¦ÓÃÆô¶¯Ê±×°Ôؾ²Ì¬Îı¾£º
1.´´½¨¼Ì³ÐÁËHttpServletÀàµÄ×ÓÀ࣬ÔÚweb.xmlÖÐÅäÖÃÕâServletʱÉèÖÃload-on-startupÊôÐÔ£º
someclass
somepackage.SomeClass1
2.ÔÚÕâ¸öServletµÄinit()·½·¨Öд´½¨java.util.PropertiesÀà
3.»ñÈ¡µ±Ç°WebÓ¦ÓõÄServletContext¶ÔÏó
4.½«WEB-INFĿ¼ÏµÄÊôÐÔÎļþ¶ÁÈëµ½ÊäÈëÁ÷InputStreamÖУº
InputStream in = context.getResourceAsString("WEB-INF/someproperties.properties");
5.½«ÊäÈëÁ÷¼ÓÔص½ÊôÐÔ¶ÔÏóÖÐ
ps.load(in);
6.½«ÊôÐÔ¶ÔÏó±£´æµ½ÉÏ
context.setAttribute("attributeName",ps);
Ê®ËÄ¡¢ÈçºÎ´´½¨±êÇ©´¦ÀíÀࣺ
1.ÒýÈë±ØÐèµÄ×ÊÔ´£º
import javax.servlet.jsp.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
2.¼Ì³ÐTagSupportÀಢ¸²¸ÇdoStartTag()/doEndTag()·½·¨
3.´ÓServletContext¶ÔÏóÖлñÈ¡java.util.Properties¶ÔÏó
4.´ÓProperties¶ÔÏóÖлñÈ¡key¶ÔÓ¦µÄÊôÐÔÖµ
5.¶Ô»ñÈ¡µÄÊôÐÔ½øÐÐÏàÓ¦µÄ´¦Àí²¢Êä³ö½á¹û
Ê®Îå¡¢´´½¨±êÇ©¿âÃèÊöÎļþ(Tag Library Descriptor)£º
1.±êÇ©¿âÃèÊöÎļþ£¬¼ò³ÆTLD£¬²ÉÓÃXMLÎļþ¸ñʽ£¬¶¨ÒåÁËÓû§µÄ±êÇ©¿â¡£TLDÎļþÖеÄÔªËØ¿ÉÒÔ·Ö³É3Àࣺ
A.£º±êÇ©¿âÔªËØ
B.£º±êÇ©ÔªËØ
C.£º±êÇ©ÊôÐÔÔªËØ
2.±êÇ©¿âÔªËØÓÃÀ´É趨±êÇ©¿âµÄÏà¹ØÐÅÏ¢£¬ËüµÄ³£ÓÃÊôÐÔÓУº
A.shortname£º Ö¸¶¨Tag LibraryĬÈϵÄǰ׺Ãû(prefix)
B.uri£º É趨Tag LibraryµÄΩһ·ÃÎʱíʾ·û
3.±êÇ©ÔªËØÓÃÀ´¶¨ÒåÒ»¸ö±êÇ©£¬ËüµÄ³£¼ûÊôÐÔÓУº
A.name£º É趨TagµÄÃû×Ö
B.tagclass£º É趨TagµÄ´¦ÀíÀà
C.bodycontent£º É趨±êÇ©µÄÖ÷Ìå(body)ÄÚÈÝ
1).empty£º±íʾ±êÇ©ÖÐûÓÐbody
2).JSP£º±íʾ±êÇ©µÄbodyÖпÉÒÔ¼ÓÈëJSP³ÌÐò´úÂë
3).tagdependent£º±íʾ±êÇ©ÖеÄÄÚÈÝÓɱêÇ©×Ô¼ºÈ¥´¦Àí
4.±êÇ©ÊôÐÔÔªËØÓÃÀ´¶¨Òå±êÇ©µÄÊôÐÔ£¬ËüµÄ³£¼ûÊôÐÔÓУº
A.name£ºÊôÐÔÃû³Æ
B.required£ºÊôÐÔÊÇ·ñ±ØÐèµÄ£¬Ä¬ÈÏΪfalse
C.rtexprvalue£ºÊôÐÔÖµÊÇ·ñ¿ÉÒÔΪrequest-time±í´ïʽ£¬Ò²¾ÍÊÇÀàËÆÓÚ< %=¡% >µÄ±í´ïʽ
Ê®Áù¡¢ÔÚWebÓ¦ÓÃÖÐʹÓñêÇ©£º
1.Èç¹ûWebÓ¦ÓÃÖÐÓõ½ÁË×Ô¶¨ÒåJSP±êÇ©£¬Ôò±ØÐëÔÚweb.xmlÎļþÖмÓÈëÔªËØ£¬ËüÓÃÓÚÉùÃ÷ËùÒýÓõıêÇ©ËùÔڵıêÇ©¿â
/sometaglib
/WEB-INF/someTLD.tld
2.£ºÉ趨Tag LibraryµÄΩһ±êʾ·û£¬ÔÚWebÓ¦ÓÃÖн«¸ù¾ÝËüÀ´ÒýÓÃTag Libray
3.£ºÖ¸¶¨ºÍTag Library¶ÔÓ¦µÄTLDÎļþµÄλÖÃ
4.ÔÚJSPÎļþÖÐÐèÒª¼ÓÈë<% @ taglib% >Ö¸ÁîÀ´ÉùÃ÷¶Ô±êÇ©¿âµÄÒýÓá£ÀýÈ磺
<% @ taglib prefix = ¡°somePrefix¡± uri = "/someuri" %>
5.prefix±íʾÔÚJSPÍøÒ³ÖÐÒýÓÃÕâ¸ö±êÇ©¿âµÄ±êǩʱµÄǰ׺£¬uriÓÃÀ´Ö¸¶¨Tag LibraryµÄ±êʶ·û£¬Ëü±ØÐëºÍweb.xmlÖеÄÊôÐÔ±£³ÖÒ»Ö¡£
ÍƼöÐÅÏ¢
- ÔÝÎ޼Ǽ
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- java urlÖØд¼¼Êõ(UrlReWriter)
- [ת]JavaµÄÊý×飨Array£©¡¢Vector¡¢ArrayLis....
- jsp»·¾³ÏÂajaxÂÒÂëÎÊÌâµÄ½â¾ö
- JSP¼¼Êõ Ö¸Áî ÂÒÂëÎÊÌâ ÔËÐÐÔÀíºÍ¾Å´óÒþʽ¶ÔÏó web¿ª·¢µÄË....
- JAVA ˮӡ ͼƬ ÎÄ×Ö
- java¶þ½øÖÆ£¬ÔÂë¡¢·´Âë¡¢²¹Â롢λÔËËã
- Java WebÓ¦ÓÃÆô¶¯¼ä¸ôÖ´ÐеijÌÐò
- jspÉú³ÉxmlÎļþʾÀý
- javaÖÐÀà±äÁ¿¡¢Àà·½·¨¡¢ÊµÀý±äÁ¿¡¢ÊµÀý·½·¨
- JSPÒ³ÃæµÄÎåÖÖÌøת·½·¨
ÆÀÂÛ