JSPÒ³ÃæÌøת´óÈ«
JSPÒ³ÃæÌøת´óÈ«
JSPÖеÄÌøת£º
(1). forward()·½·¨
ʹÓõ½javax.servlet.RequestDispatcherÀà
RequestDispatcher rd = getServletContext().getRequestDispatcher("url");
rd.forward(requestVar,requestVar); //´«µÝservletµÄÈë¿Ú²ÎÊý
/*forwardº¯ÊýÒѾ°ÑÔÒ³ÃæµÄrequest,response¶ÔÏó´«ÈëеÄÒ³Ã棬Òò´ËÕâоÉÒ³ÃæÓµÓÐÏàͬµÄrequest,response¶ÔÏó¡£request.getparameter("var")¾Í¿ÉÒԵõ½ÏàÓ¦µÄÖµ.*/
/*forward()ÊÇÖ±½ÓÔÚserver×öµÄ£¬ä¯ÀÀÆ÷²¢²»ÖªµÀ£¬Ò²²»ºÍä¯ÀÀÆ÷´ò½»µÀ£¬ä¯ÀÀÆ÷µÄµØÖ·²»±ä»¯¡£*/
¼´£º
getServletContext().getRequestDispatcher("url").forward(requestVar,responseVar);
·þÎñÆ÷¶ËServlet½øÐÐתÏòµÄ4ÖÖ·½·¨£º
1.ServletContextµÄgetRequestDispatcher()
2.ServletContextµÄgetNamedDispatcher()
3.ServletRequestµÄgetRequestDispatcher()
4.ServletResponseµÄsendredirect()½øÐÐתÏò¡£
forward·½·¨£¬ÒòΪÕâЩÕâÑù±È½Ï¸ßЧ¡£Ö»ÓÐÔÚforward·½·¨²»ÄÜʹÓÃʱ£¬ÔÙʹÓÃservletresponseµÄsendredirect()·½·¨¡£
(2).response.sendRedirect(url);
ÆäʵÊÇÏòä¯ÀÀÆ÷·¢ËÍÒ»¸öÌØÊâµÄHeader£¬È»ºóÓÉä¯ÀÀÆ÷À´×öתÏò£¬×ªµ½Ö¸¶¨µÄÒ³Ã棬ËùÒÔÓÃsendRedirectʱ£¬ä¯ÀÀÆ÷µÄµØÖ·À¸ÉÏ¿ÉÒÔ¿´µ½µØÖ·µÄ±ä»¯¡£ÐÂÒ³Ãæ²»ÄÜ´¦Àí¾ÉÒ³ÃæµÄpagecontext(request,response,...)¶ÔÏó.
ÔÚresponse.sendRedirectÖ®ºó£¬Ó¦¸Ã½ô¸úÒ»¾äreturn;
(3).HTMLÓïÑÔµÄ×Ô¶¯Ìøת
<html>
<head>
<meta http-equiv="refresh" content="0;url="http://www.baidu.com">
0Êǵȴýʱ¼ä£¬Èç¹ûÉèÖÃΪ5±íʾµÈ´ý5sºó¿ªÊ¼Ìøת
</head>
…………
(4).JavaScriptÌøת
A: <script languate="javascript">
&n
Ïà¹ØÎĵµ£º
jspÒ³ÃæʹÓÃstruts2µÄproperty±êÇ©Êä³öÈçÏÂÄÚÈÝ
<s:property value="detailinfo"/> ÆäÖУ¬detailinfo="<strong>abc</strong>"£»
ºÃÏñûÊ£¬ÎÊÌâ³öÏÖÁË£¬ÔÚjspÒ³ÃæÉÏÏÔʾ³öÁË<strong>abc</strong>
Ò»¿´Ò³ÃæÔ´Â룬·¢ÏÖ£¬Ô´´úÂëÖÐÒѾ±ä³ÉÁË
< strong&a ......
Á½ÄêÇ°£¬ÔøÓÐһλǰ±²¶ÔÎÒ˵¹ý£º¿ª·¢Ò»¸öÊôÓÚÄã×Ô¼ºµÄÍøÕ¾£¬È»ºóÿÌ컨һµã¿ÕÏеÄʱ¼äÈ¥¾ÓªÒ»Ï£¬ÖÕÓÐÒ»Ì죬Äã»á·¢¾õËüÊǷdz£ÓÐÓõġ£¸Õ¿ªÊ¼µÄʱºò£¬ÎÒûÓаÑÕâЩ»°·ÅÔÚÐÄÉÏ£¬ÂýÂýµØ£¬ÎҲŷ¢¾õÕâλǰ±²ËµµÄ»°ÊǺÜÓеÀÀíµÄ¡£¼ÙÉèÁ½ÄêÇ°¿ªÊ¼¾ÓªÒ»¸öÍøÕ¾£¬Í¨¹ýÕâÁ½ÄêµÄÍƹãºÍÔËÓª£¬Ëµ²»¶¨µ½Ï ......
ΪÁ˼õÇá·þÎñÆ÷ѹÁ¦£¬½«ÔÀ´µÄÎÄÕ¹ÜÀíϵͳÓÉJSPÎļþµÄ´ÓÊý¾Ý¿âÖÐÈ¡Êý¾ÝÏÔʾ¸ÄΪÓÉjspÉú³É¾²Ì¬htmlÎļþºóÖ±½Ó·ÃÎÊhtmlÎļþ¡£Ê×ÏÈÓ¦´´½¨Ò»¸öÄ£°åÎļþ£¬ÎļþÃûºÍÎļþºó׺¿ÉÒÔËæÒ⣬µ«ÎÒÒ»°ã³£ÓõĻ¹ÊÇ *.template £¬Òò´Ë£¬ÕâÀï¾ÍÒÔ template.template ΪÀý( ½«Ä£°åÎļþ·ÅÈë /WEB-INF/templates/ Îļþ¼ÐÏ )£ºÏÂÃæÊÇÒ»¸ö¼òµ¥µÄ ......
Ò»¡¢JSPÒ³ÃæÏÔʾÂÒÂë
¶þ¡¢±íµ¥Ìá½»ÖÐÎÄʱ³öÏÖÂÒÂë
Èý¡¢Êý¾Ý¿âÁ¬½Ó
´ó¼ÒÔÚJSPµÄ¿ª·¢¹ý³ÌÖУ¬¾³£³öÏÖÖÐÎÄÂÒÂëµÄÎÊÌ⣬¿ÉÄÜÒ»ÖÁÀ§ÈÅ×ÅÄú£¬ÎÒÏÖÔÚ°ÑÎÒÔÚJSP¿ª·¢ÖÐÓöµ½
µÄÖÐÎÄÂÒÂëµÄÎÊÌâ¼°½â¾ö°ì·¨Ð´³öÀ´¹©´ó¼Ò²Î¿¼¡£
Ò»¡¢JSPÒ³ÃæÏÔʾÂÒÂë
ÏÂÃæµÄÏÔʾҳÃæ(display.jsp)¾Í³öÏÖÂÒÂ룺
<html>
<head>
<tit ......
Äãʱ³£±»¿Í»§±§Ô¹JSPÒ³ÃæÏìÓ¦ËٶȺÜÂýÂð£¿ÄãÏë¹ýµ±¿Í»§·ÃÎÊ´ÎÊý¾çÔöʱ£¬ÄãµÄWEBÓ¦ÓÃÄܳÐÊÜÈÕÒæÔö¼ÓµÄ·ÃÎÊÁ¿Âð£¿
±¾ÎĽ²ÊöÁ˵÷ÕûJSPºÍservletµÄһЩ·Ç³£ÊµÓõķ½·¨£¬Ëü¿ÉʹÄãµÄservletºÍJSPÒ³ÃæÏìÓ¦¸ü¿ì£¬À©Õ¹ÐÔ¸üÇ¿¡£¶øÇÒÔÚÓû§ÊýÔö¼ÓµÄÇé¿öÏ£¬ÏµÍ³¸ºÔØ»á³ÊÏÖ³öƽ»¬Éϳ¤µÄÇ÷ÊÆ¡£ÔÚ±¾ÎÄÖ ......