×î½üÊÕµ½Ò»¸öÏîÄ¿µÄÔ´´úÂ룬²¿ÊðÒÔºó´ò¿ªÒ³Ãæ·¢ÏÖJSPÒ³ÃæÖеÄEL±í´ïʽ¶¼Ã»ÓнâÎö£¬¶¼ÊÇÔÑùÏÔʾ¡£
ÉÏÍøËÑË÷ÁËÒ»ÏÂÔÒò£¬ÔÀ´ÊÇServlet°æ±¾µÄÎÊÌâ¡£ÔÀ´ServletÖпÉÒÔÉ趨ÊÇ·ñ½âÎöEL±í´ïʽ£¬Ö»ÓÐ2.4°æ±¾µÄServletĬÈÏÊǽâÎöEL±í´ïʽµÄ£¬¶øÆäËû°æ±¾ÊÇĬÈϲ»½âÎöEL±í´ïʽ£¬²éÁËһϳÌÐò£¬¹ûÈ»ÓõIJ»ÊÇ2.4°æ±¾¡£ÓÚÊÇ°Ñweb.xmlÖÐʹÓõÄ2.5°æ±¾µÄServlet¸Ä³ÉÁË2.4°æ±¾µÄ¡£
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >
Ìæ»»³É
<web-app version="2.4" 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
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
ÖØв¿Êð Æô¶¯ºó¾Í¿ÉÒÔ½âÎöEL±í´ïʽÁË
µ±È» ÆäËû°æ±¾µÄServletÖ»ÊÇĬÈϲ»½âÎöEL±í´ïʽ µ«ÊÇÔÚ ......
jspѧϰÐĵÃ
ѧϰJSP¼¼ÊõÒ²¿ì°ëÄê¶àÁË°É£¬×Ô¼ºÒ²¶¯ÊÖ±àдÁËһЩ¼òµ¥µÄ¶¯Ì¬ÍøÒ³°É¡£ÖÚËùÖÜÖª¶¯Ì¬ÍøÒ³Èý´ó¼¼ÊõASP£¬JSP£¬PHP»ù±¾ÉÏÊÇÈý·ÖÌìÏ£¬µ±È»»¹ÓÐÆäËûÓïÑÔÏñRuby£¬PythonµÈÒ²Õ¼¾Ý²»Ð¡µÄ·Ý¶î¡£
ѧϰJSP¹ý³ÌÖÐÎҸд¥×îÉîµÄÊÇÈçϼ¸µã£º
1.JSPÊÇÒ»ÖÖ±íʾ²ãµÄ¼¼Êõ
ÎÒÈÏΪÈç¹û²»ÖªµÀJSTLºÍEL±í´ïʽ¸ù±¾Ëµ²»ÉÏѧºÃÁËJSP¼¼Êõ¡£Ñ§¹ýJSPÒ»¶¨¶ÔÕâЩ½Å±¾ÔªËغÜÊìϤ:
(1)<%! %> ÉùÃ÷½Å±¾ÔªËØ
(2)<%= %> ±í´ïʽ½Å±¾ÔªËØ
(3)<% %> scriptlet½Å±¾ÔªËØ
¿ÉÒÔÔÙÕâЩ½Å±¾ÔªËØÖÐÖ±½Ó²åÈëJava´úÂ룬ÓÃÓÚÁ÷³Ì¿ØÖƺÍÓ¦ÓÃÂß¼£¬¿´ËÆÊ®·Ö¼òµ¥ºÍ·½±ã£¬µ«Ç¡Ç¡ÕâЩ½Å±¾ÔªËØçèÎÛÁ˱íʾ²ã¡£ÕâЩ½Å±¾ÔªËØÊÇJSPÔçÆÚ°æ±¾ÒÅÁôÏÂÀ´µÄÎÊÌ⣬ÔÚJSP2.0ÖÐÒýÈëÁËEL²¢½áºÏJSTL»ù±¾ÉϽâ¾öÁËÉÏÊöÎÊÌ⣬ʹµÃÎÒÃÇ¿ÉÒÔ±à³ö²»º¬Óнű¾µÄJSP´úÂ룬ÈÃJSPÊÇÕæÕýÒâÒåÉÏÊÇÓÃÓÚ±íʾ¡£
2.JSPʵÖÊÊÇServlet
´ËÍâÈç¹û²»ÊìϤServletÒ²³Æ²»ÉϾ«Í¨JSP£¬¾¿Æä±¾ÖÊÀ´¿´JSP×îÖÕÒª±àÒë³ÉJava×Ö½ÚÂë¼´.classÎļþ¡£´ó¼Ò¿ÉÒÔÔÚTomcat 6.0\work\C ......
JSPµÄ»á»°¸ú×Ù¼¼Êõ
Cookie£º·þÎñÆ÷ÔÚÒ»¸öÓ¦´ðÊײ¿´«µÝ¸øä¯ÀÀÆ÷µÄÃû³Æ/Öµ¶Ô¡£ä¯ÀÀÆ÷±£´æµÄʱ¼äÓÉcookieµÄ¹ýÆÚʱ¼äÊôÐÔÀ´Ö¸¶¨¡£µ±ä¯ÀÀÆ÷Ïòij¸ö·þÎñÆ÷·¢ËÍÒ»¸öÇëÇóʱ£¬Ëü»á¼ì²éÆä±£´æµÄcookie£¬²¢ÔÚÇëÇóÊײ¿Öаüº¬´Óͬһ̨·þÎñÆ÷ÉϽÓÊÕµ½µÄËùÓÐcookie¡£
Session tracking:ÔÚä¯ÀÀÆ÷ºÍ·þÎñÆ÷Ö®¼ä²»Ö±½Ó´«ËÍËùÓеÄ״̬ÐÅÏ¢£¬¶øÖ»ÊÇ´«µÝ±íʾ·û£¨session ID£©¡£ä¯ÀÀÆ÷·¢ËÍsessionID,·þÎñÆ÷¸ú×ÙÓë¸Ã»á»°Ïà¹ØÁªµÄËùÓÐÐÅÏ¢¡£´«µÝsessionID¿ÉÒÔͨ¹ýcookieºÍURL¸´Ð´¼¼Êõ£¬´ó²¿·ÖÈÝÆ÷¶¼Ö§³ÖÕâÁ½ÖÖ¼¼Êõ¡£·þÎñÆ÷ÎÞ·¨·Ö±æÓû§ÊÇ·ñ¹Ø±ÕÁËä¯ÀÀÆ÷£¬Òò´Ë¹Ø±Õä¯ÀÀÆ÷Òâζ×ÅÓëÏÈÇ°µÄ»á»°¹ØÁªµÄËùÓлỰÊý¾Ý¶¼±£ÁôÔÚ·þÎñÆ÷ÉÏ£¬Ö±µ½»á»°³¬Ê±£¬·þÎñÆ÷Ïú»Ù»á»°¶ÔÏñ¡£
®¸ú×Ùͬһ»á»°ÖеÄÇëÇóµÄ»á»°ID¿ÉÒÔÓжàÖÖ·½·¨£¬Ö÷ÒªÓÐcookieºÍurl¸´Ð´¡£
URL¸´Ð´£º°Ñ»á»°ID±àÂëÔÚURLÖС£
Àý£ºcounter.jjsp;jsessionnid=be8d697876787876befdbde898789098980
ÕâÑù£¬¼´Ê¹ä¯ÀÀÆ÷²»Ö§³Öcookie£¬Ò²Äܹ»ÊµÏֻỰ¸ú×Ù¡£
¶ÔÓÚURL¸´Ð´£¬·þÎñÆ÷´ÓÇëÇóµÄURIÖÐÌáÈ¡³ö»á»°ID£¬²¢°Ñ¸ÃÇëÇóÓ ......
×òÌìÔÚ䶫Î÷µÄʱºò£¬Êý¾Ý¿âÓõıàÂëÊǣգԣƣ£¸£¬Ò³ÃæÒ²Êǣգԣƣ£¸£¬È»ºó´æ½øÊý¾Ý¿âµÄʱ·¢ÏÖ»¹ÊÇÂÒÂë¡£ÖÐÎĵÄʱºò£¬Ëæºó£ä£å£â£õ£ç£¬²éµ½£Á£ã£ô£é£ï£îÀïÃæµÃµ½µÄ±íµ¥ÄÚÈÝÒ²ÊÇÂÒÂ룬¹þ¹þ
ÎÊÌâÕÒµ½ÁË£¬ÔÀ´Êǣƣï£ò£í±íµ¥»òÕßÆäËûµØ·½ÓÐÎÊÌâ
ºóÀ´ÔÚ£÷£å£â£®£ø£í£ìÖмÓÉ϶ԣӣð£ò£é£î£ç±àÂëµÄ¿ØÖÆÓï¾ä£¬ºÃÁË£®£®£®ºÇºÇ
´úÂëÈçÏ£º
<!-- Spring´¦ÀíÂÒÂëµÄ¹ýÂËÆ÷-->
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<!--ÄãÐèÒªµÄ±àÂë¸ñʽ-->
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
ºÇºÇ£¬Ï£Íû¶Ô´ó¼ÒÓÐÓà ......
ת×Ô£ºhttp://www.centospub.com/make/servlet.html
Ç°¡¡¡¡ÑÔ
¡¡¡¡Ëùν Java Servlet £¬ÊÇÖ¸Óà Java ÓïÑÔ£¬ÊµÏÖ¶¯Ì¬ÍøÒ³µÄ´´½¨µÄ¹¦ÄÜ£¬Ò»°ã°Ñ¼òµ¥µÄ°ÑËü³ÆΪ“Servlet”£¨ÎÞÖÐÎÄÒëÎÄ£©µÄÇé¿ö±È½Ï³£¼û¡£ºÍËü´¦ÓÚͬµÈÀà±ðµÄ¼¼Êõ»¹ÓÐÎÒÃÇÖªµÀµÄPerl¡¢PHP¡¢ASPµÈµÈ¡£ServletËãÊÇJ2EEÖеÄÒ»²¿·Ö£¬ËùÒÔÔÚÆóÒµÓ¦Ó÷½Ã棬Servlet¼¼Êõ±»¹ã·ºµÄÓ¦ÓÃ×Å¡£¶øËùνµÄJSPÊÇServlet¼¼ÊõµÄÑÓÉ죬Servlet³ÌÐò¾ÍÊÇͨ¹ýJSPÀ´×Ô¶¯Éú³ÉµÄ¡£Í¨³£ServletºÍJSP±»»ìΪһ̸µÄÇé¿ö±È½Ï¶à¼û£¬µ«ÑϸñÉÏ˵£¬ServletºÍJSPÊÇÁ½ÖÖ²»Í¬µÄ¼¼Êõ…µ«Ò²ÕýÒòΪËüÃÇͨ³£×÷Ϊ“´îµµ”£¬JSPÒ²±»ÈÏ×÷ÊÇServletµÄÒ»ÖÖ¹¦ÄÜ¡£
¡¡¡¡ÏÂÃæÎÒÃǾͽéÉÜÒ»ÏÂÔÚCentOSϹ¹½¨Servlet/JSP·þÎñÆ÷µÄ·½·¨¡£
±ØÒª×é¼þµÄ°²×°
[1] жÔØCentOSϵͳĬÈϵÄJava±àÒëÆ÷--gcj¡£
¡¡¡¡ÎªÁËĬÈÏʹÓÃSunµÄjavac×÷ΪJavaµÄ±àÒëÆ÷£¬Ê×ÏÈɾ³ýCentOSϵͳĬÈϵÄJava±àÒëÆ÷--gcj¡£
[root@sample ~]# rpm -qa | grep gcj¡¡ ← È·ÈÏgcjµÄ°æ±¾ºÅ
libgcj-3.4.5-2
libgcj-devel-3.4.5-2
java-1.4.2-gcj-compat-1.4.2.0-27jpp¡¡ ← ¸ù¾Ý°æ±¾ºÅжÔØgcj
[root@sample ~]# yum -y remove java-1.4.2-gcj-compat¡¡ ← ж ......
ÔÚJSPÖÐÒýÓÃjsÎļþ»á·¢ÉúÒýÓò»µ½µÄÎÊÌ⣺
ÔÚwebÏîÄ¿À´æÔÚWEB-INFÎļþĿ¼£¬ÎҵĴíÎó×ö·¨ÊÇ°Ñjs£¬image£¬CSS¶¼·ÅÔÚ´ËÎļþ¼ÐÏ¡£×î³õÒÔΪÊÇÏà¶Ô·¾¶Óë¾ø¶Ô·¾¶¸ã´íÁË£¬µ«ÊÇÔõôÐÞ¸ÄÒ²ÎÞ·¨½â¾öÎÊÌâ¡£µ÷ÓÃjsʱ×ÜÊǻᱨȱÉÙ¶ÔÏó£¬×îºóÁ˽âÊÇÒòΪWEB-INFÕâÀïµÄ¶«Î÷ÊDz»ÈÃÖ±½Ó·ÃÎʵġ£ËùÒԸı䷽·¨°ÑÕâЩÎļþ¾Í¶¼·ÅÔÚÁ˸ùĿ¼Ï£¬ÒýÓ÷½Ê½ÊÇ<script src="js/ui.datepicker.js" type="text/javascript"></script>ÕâÑù¾ÍÕýÈ·ÁË
µ÷ÓÃjQueryÈÕÆڿؼþµÄʱºò£¬»áдһ¸öÖÐ-Ó¢ÎÄת»»µÄjs£¬±¾Éí¿Ø¼þÊÇÓ¢Îĵģ¬¼ÓÈëÖÐÎĵÄÎĵµ¾Í»á×Ô¶¯¼ÓÔسÉΪÖÐÎÄÏÔʾ£¬µ«ÊǼÓÔØʱ³öÏÖÖÐÎÄÂÒÂëµÄÇé¿ö£¬×îºó½â¾öÊÇÒòΪjsÎļþÊôÐÔûÓиijÉutf-8µÄ¸ñʽ¡£ ......