JSP¶¯×÷
JSP¶¯×÷ÀûÓÃXMLÓï·¨¸ñʽµÄ±ê¼ÇÀ´¿ØÖÆServletÒýÇæµÄÐÐΪ¡£ÀûÓÃJSP¶¯×÷¿ÉÒÔ¶¯Ì¬µØ²åÈëÎļþ¡¢ÖØÓÃJavaBean×é¼þ¡¢°ÑÓû§Öض¨Ïòµ½ÁíÍâµÄÒ³Ã桢ΪJava²å¼þÉú³ÉHTML´úÂë¡£
JSP¶¯×÷°üÀ¨£º
jsp:include£ºÔÚÒ³Ãæ±»ÇëÇóµÄʱºòÒýÈëÒ»¸öÎļþ¡£
jsp:useBean£ºÑ°ÕÒ»òÕßʵÀý»¯Ò»¸öJavaBean¡£
jsp:setProperty£ºÉèÖÃJavaBeanµÄÊôÐÔ¡£
jsp:getProperty£ºÊä³öij¸öJavaBeanµÄÊôÐÔ¡£
jsp:forward£º°ÑÇëÇóתµ½Ò»¸öеÄÒ³Ãæ¡£
jsp:plugin£º¸ù¾Ýä¯ÀÀÆ÷ÀàÐÍΪJava²å¼þÉú³ÉOBJECT»òEMBED±ê¼Ç¡£
¡¡¡¡ 13.1 jsp:include¶¯×÷
¡¡¡¡ ¸Ã¶¯×÷°ÑÖ¸¶¨Îļþ²åÈëÕýÔÚÉú³ÉµÄÒ³Ãæ¡£ÆäÓï·¨ÈçÏ£º
£¼jsp:include page="relative URL" flush="true" /£¾
¡¡¡¡ Ç°ÃæÒѾ½éÉܹýincludeÖ¸ÁËüÊÇÔÚJSPÎļþ±»×ª»»³ÉServletµÄʱºòÒýÈëÎļþ£¬¶øÕâÀïµÄjsp:include¶¯×÷²»Í¬£¬²åÈëÎļþµÄʱ¼äÊÇÔÚÒ³Ãæ±»ÇëÇóµÄʱºò¡£jsp:include¶¯×÷µÄÎļþÒýÈëʱ¼ä¾ö¶¨ÁËËüµÄЧÂÊÒªÉÔ΢²îÒ»µã£¬¶øÇÒ±»ÒýÓÃÎļþ²»ÄÜ°üº¬Ä³Ð©JSP´úÂ루ÀýÈç²»ÄÜÉèÖÃHTTPÍ·£©£¬µ«ËüµÄÁé»îÐÔÈ´ÒªºÃµÃ¶à¡£
¡¡¡¡ ÀýÈ磬ÏÂÃæµÄJSPÒ³Ãæ°Ñ4ÔòÐÂÎÅÕªÒª²åÈëÒ»¸ö“What's New ?”Ò³Ãæ¡£¸Ä±äÐÂÎÅժҪʱֻÐè¸Ä±äÕâËĸöÎļþ£¬¶øÖ÷JSPÒ³ÃæÈ´¿ÉÒÔ²»×÷Ð޸ģº
¡¡¡¡ WhatsNew.jsp
£¼!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"£¾
£¼HTML£¾
£¼HEAD£¾
£¼TITLE£¾What's New£¼/TITLE£¾
£¼/HEAD£¾
£¼BODY BGCOLOR="#FDF5E6" TEXT="#000000" LINK="#0000EE"
VLINK="#551A8B" ALINK="#FF0000"£¾
£¼CENTER£¾
£¼TABLE BORDER=5 BGCOLOR="#EF8429"£¾
£¼TR£¾£¼TH CLASS="TITLE"£¾
What's New at JspNews.com£¼/TABLE£¾
£¼/CENTER£¾
£¼P£¾
Here is a summary of our four most recent news stories:
£¼OL£¾
£¼LI£¾£¼jsp:include page="news/Item1.html" flush="true"/£¾
£¼LI£¾£¼jsp:include page="news/Item2.html" flush="true"/£¾
£¼LI£¾£¼jsp:include page="news/Item3.html" flush="true"/£¾
£¼LI£¾£¼jsp:include page="news/Item4.html" flush="true"/£¾
£¼/OL£¾
£¼/BODY£¾
£¼/HTML£¾
¡¡¡¡ 13.2 jsp:useBean¶¯×÷
¡¡¡¡ jsp:useBean¶¯×÷ÓÃÀ´×°ÔØÒ»¸ö½«ÔÚJSPÒ³ÃæÖÐʹÓõÄJavaBean¡£Õâ¸ö¹¦Äܷdz£ÓÐÓã¬ÒòΪËüʹµÃÎÒÃǼȿÉÒÔ·¢»ÓJava×é¼þÖØÓõÄÓÅÊÆ£¬Í¬Ê±Ò²±ÜÃâÁËËðʧJSPÇø±ðÓÚServletµÄ·½±ãÐÔ¡£jsp:useBean¶¯×÷×î¼òµ¥µÄÓ﷨Ϊ£º
£¼jsp:useBean id="name" class="package.class" /£¾
¡¡¡¡
Ïà¹ØÎĵµ£º
JSPÖи÷ÖÖÄÚÖöÔÏó
web½»»¥µÄ×î»ù±¾µ¥Î»ÊÇhttpÇëÇó¡£Ã¿¸öÓû§´Ó½øÈëÍøÕ¾µ½À뿪ÍøÕ¾Õâ¶Î¹ý³Ì³ÆΪһ¸öHTTP»á»°£¬Ò»¸ö·þÎñÆ÷µÄÔËÐйý³ÌÖлáÓжà¸öÓû§·ÃÎÊ£¬¾ÍÊǶà¸öHTTP»á»°¡£×÷ÓÃÓò½âÊÍÈçÏ£º
1.application£º·þÎñÆ÷Æô¶¯µ½Í£Ö¹µÄÕâ¶Îʱ¼ä
2.session£ºHTTP»á·¢¿ªÊ¼µ½½áÊøµÄÕâ¶Îʱ¼ä
3.request£ºHTTPÇëÇó¿ªÊ¼µ½½áÊ ......
ÔÚWEBÓ¦ÓÃÖÐ,Èç¹ûʹÓÃjsp×÷Ϊview²ãµÄÏÔʾģ°å,¶¼»á±»¿Õ¸ñ/¿Õ»»ÐÐÎÊÌâËùÀ§ÈÅ.
Õâ¸öÎÊÌâµ±ÄêÒ²À§ÈÅÁËÎұȽϳ¤µÄʱ¼ä.ÒòΪÔÚjspÄÚʹÓõÄEL±êÇ©ºÍÆäËû±êǩʱ,»á²úÉú´óÁ¿µÄ¿Õ¸ñºÍ»»Ðзû.ÀýÈç:
------- start ----------
<c:choose>
<c:when test="${fn:length(mainPageList)>1&}&q ......
´íÎó£º
String realPath = " http:// " + request.getServerName() + " : " + request.getServerPort() + request.getContextPath();
String realPath = " http:// " + request.getSer ......
1.RequestDispatcher.forward()
¡¡¡¡ ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´«µÝHTTPÇëÇó´Óµ±Ç°µÄServlet or JSPµ½ÁíÍâÒ»¸öServlet,JSP »òÆÕͨHTMLÎļþ,Ò²¼´ÄãµÄformÌá½»ÖÁa.jsp,ÔÚa.jspÓõ½ÁËforward()Öض¨ÏòÖÁb.jsp,´ËʱformÌá½»µÄËùÓÐÐÅÏ¢ÔÚ b.jsp¶¼¿ÉÒÔ»ñµÃ,²ÎÊý×Ô¶¯´«µÝ.
¡¡¡¡µ«forward()ÎÞ·¨Öض¨ÏòÖ ......
¸ÅÊö
¡¡¡¡Java Server Pages£¨JSP£©Ê¹µÃÎÒÃÇÄܹ»·ÖÀëÒ³ÃæµÄ¾²Ì¬HTMLºÍ¶¯Ì¬²¿·Ö¡£HTML¿ÉÒÔÓÃÈκÎͨ³£Ê¹ÓõÄWebÖÆ×÷¹¤¾ß±àд£¬±àд·½Ê½Ò²ºÍÔÀ´µÄÒ»Ñù£»¶¯Ì¬²¿·ÖµÄ´úÂë·ÅÈëÌØÊâ±ê¼ÇÖ®ÄÚ£¬´ó²¿·ÖÒÔ“£¼%”¿ªÊ¼£¬ÒÔ“%£¾”½áÊø¡£
¡¡¡¡ÀýÈ磬ÏÂÃæÊÇÒ»¸öJSPÒ³ÃæµÄƬ¶Ï£¬Èç¹ûÎÒÃÇÓÃhttp://host/OrderConfirm ......