JSPÖж¯Ì¬INCLUDEÓ뾲̬INCLUDEµÄÇø±ð
ÎÒÃǶ¼ÖªµÀÔÚjspÖÐincludeÓÐÁ½ÖÖÐÎʽ,·Ö±ðÊÇ
<%@ include file=" "%>
<jsp:include page=" " flush="true"/>
ǰÕßÊÇÖ¸ÁîÔªËØ¡¢ºóÕßÊÇÐÐÎªÔªËØ.
ͨ³£µ±Ó¦ÓóÌÐòÖÐËùÓеÄÒ³ÃæµÄijЩ²¿·Ö(ÀýÈç±êÌâ¡¢Ò³½ÅºÍµ¼º½À¸)¶¼ÏàͬµÄʱºò,ÎÒÃǾͿÉÒÔ¿¼ÂÇÓÃinclude.¾ßÌåÔÚÄÄЩʱºòÓÃ<%@ include file=" "%>,ÄÄЩʱºòÓÃ<jsp:include page=" " flush="true"/>.ÕâÖÖÐÎʽ.Ê×ÏÈÒªÃ÷°×µÄÊÇËüÃÇÖ®¼äµÄÇø±ð.
<%@ include file=" "%>,jspµÄincludeÖ¸ÁîÔªËØ¶ÁÈëÖ¸¶¨Ò³ÃæµÄÄÚÈÝ.²¢°ÑÕâЩÄÚÈݺÍÔÀ´µÄÒ³ÃæÈںϵ½Ò»Æð.(Õâ¸ö¹ý³ÌÊÇÔÚ·Òë½×¶Î:Ò²¾ÍÊÇjsp±»×ª»¯³ÉservletµÄ½×¶Î½øÐеģ©.
ÕâÀï¶Ô·Òë½×¶Î½øÐÐÒ»ÏÂ˵Ã÷:ÎÒÃÇÖªµÀ,jspÒ³Ãæ²»ÄÜÔ·â²»¶¯µØ±»´«Ë͸øä¯ÀÀÆ÷,ËùÓеÄjspÔªËØ¶¼±ØÐëÊ×ÏÈÓÉ·þÎñÆ÷½øÐд¦Àí.ÕâÊÇͨ¹ý½«jspÒ³Ãæ×ª´ï»¯³Éservlet,È»ºóÖ´ÐÐÕâ¸öservletÀ´Íê³ÉµÄ.·þÎñÆ÷ÐèÒªÒ»¸öjspÈÝÆ÷À´´¦ÀíjspÒ³Ãæ.jspÈÝÆ÷ͨ³£ÒÔservletµÄÐÎʽÀ´ÊµÏÖ,Õâ¸öservlet¾¹ýÅäÖÃ,¿ÉÒÔ´¦Àí¶ÔjspÒ³ÃæµÄËùÓÐÇëÇó.
JspÈÝÆ÷¸ºÔð½«jspÒ³Ãæ×ª»¯³Éservlet(³ÆÎªjspÒ³ÃæÊµÏÖÀà?JSP Page implementation class),²¢±àÒëÕâ¸öservlet.ÕâÁ½²½¾Í¹¹³ÉÁË·Òë½×¶Î.
ÓÉ´ËÎÒÃǾͻáÖªµÀ:jspÒ³ÃæÊǰÑincludeÖ¸ÁîÔªËØËùÖ¸¶¨µÄÒ³ÃæµÄʵ¼ÊÄÚÈÝ(Ò²¾ÍÊÇ´úÂë¶Î)¼ÓÈëµ½ÒýÈëËüµÄjspÒ³ÃæÖÐ,ºÏ³ÉÒ»¸öÎļþºó±»jspÈÝÆ÷½«Ëüת»¯³Éservlet.¿ÉÒÔ¿´µ½Õâʱ»á²úÉúÒ»¸öÁÙʱclassÎļþºÍÒ»¸öjavaÎļþ.ÏÂÃæ¾Ù¸öÀý×Ó.
·þÎñÆ÷ÓÃtomcat,ÒýÈëÒ³ÃæµÄjspÎļþ½Ðtest.jsp.±»ÒýÈëµÄÒ³Ãæ½Ðdate.jsp.Õâ¸öjspÎļþÀï´æ·ÅµÄÊÇÒ»¸öÓйØÊ±¼äµÄjsp´úÂë,µ±Ç°µÄÉÏÏÂÎĸùÉèΪtest
//======date.jspµÄÔ´Îļþ=====//
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%
java.util.Date date=new java.util.Date();
String date_cn ="";
String dateStr = "";
switch(date.getDay())
{
case 0:date_cn ="ÈÕ"; break;
case 1:date_cn ="Ò»"; break;
case 2:date_cn
Ïà¹ØÎĵµ£º
̸JSPÓëXMLµÄ½»»¥
ʹÓÃJavaServer PagesÓÐÈýÖÖ²»Í¬µÄ·½·¨ÓÃÓÚ´¦ÀíXMLÎĵµ£¬Ã¿ÖÖ·½·¨¶¼ÓÐÀûÓÚÌá¸ß·ÖÀëÒ³Ãæ´úÂëÓëXMLÊý¾ÝµÄˮƽ£¬ÓÐÀûÓÚ¼ò»¯¿ª·¢ÍøÒ³µÄ¸´ÔӶȲ¢ÇÒ¸ÄÉÆÌá¸ß×é¼þÓëÒ³Ãæ´úÂëµÄ¿ÉÖØÓÃÐÔ¡£
¡¡¡¡JavaServer Pages ( JSP)ºÍXMLÊÇSunµÄJ2EEµÄÁ½¸öÖÁ¹Ø½ôÒªµÄ×é¼þ¡£ JSPÊÇÓÃÓÚ´´½¨Ó¦ÓóÌÐò·þÎñÆ÷¶Ë³ÌÐòµÄÓÐЧ¹¤¾ß£¬¶ø¿ ......
JSPÖи÷ÖÖÄÚÖöÔÏó
web½»»¥µÄ×î»ù±¾µ¥Î»ÊÇhttpÇëÇó¡£Ã¿¸öÓû§´Ó½øÈëÍøÕ¾µ½Àë¿ªÍøÕ¾Õâ¶Î¹ý³Ì³ÆÎªÒ»¸öHTTP»á»°£¬Ò»¸ö·þÎñÆ÷µÄÔËÐйý³ÌÖлáÓжà¸öÓû§·ÃÎÊ£¬¾ÍÊǶà¸öHTTP»á»°¡£×÷ÓÃÓò½âÊÍÈçÏ£º
1.application£º·þÎñÆ÷Æô¶¯µ½Í£Ö¹µÄÕâ¶Îʱ¼ä
2.session£ºHTTP»á·¢¿ªÊ¼µ½½áÊøµÄÕâ¶Îʱ¼ä
3.request£ºHTTPÇëÇó¿ªÊ¼µ½½áÊ ......
´íÎó£º
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()ÎÞ·¨Öض¨ÏòÖ ......
×Ô¶¯×ªÏò£¬Ò²½Ð×Ô¶¯Öض¨Ïò¡£×Ô¶¯Ìø×ª£¬Ö¸µ±·ÃÎÊÓû§µÇ½µ½Ä³ÍøÕ¾Ê±£¬×Ô¶¯½«Óû§×ªÏòÆäËüÍøÒ³µØÖ·µÄÒ»ÖÖ¼¼Êõ¡£×ªÏòµÄÍøÒ³µØÖ·¿ÉÒÔÊÇÍøÕ¾Ä򵀮äËüÍøÒ³£¬Ò²¿ÉÒÔÊÇÆäËüÍøÕ¾¡£Í¨³£Çé¿öÏ£¬ä¯ÀÀÆ÷»áÊÕµ½Ò»¸öÍøÒ³£¬¸ÃÒ³Ãæº¬ÓÐ×Ô¶¯¼ÓÔØÒ»ÆäËüÍøÒ³µÄ´úÂë¡£¸ÃÒ³ÃæÓпÉÄÜÔÚ·þÎñÆ÷¶Ë±»×ª»»£¬ÕâÑùµÄ»°£¬ä¯ÀÀÆ÷Ö»ÊÕµ½Ò»¸öÒ³Ãæ£¬¶ø×Ô¶¯×ª ......