jspºÍservletÖض¨Ïò
Ò»¡¢
ÔÚÒ»¸öÉè¼ÆÁ¼ºÃµÄWebÓ¦ÓÃÖУ¬¶¼»á×ÛºÏʹÓÃServletºÍJSP¼¼Êõ¡£Servlet¿ØÖÆÒµÎñÁ÷ת£¬JSPÔò¸ºÔðÒµÎñ´¦Àí½á¹ûµÄÏÔʾ¡£´Ëʱ£¬½«´óÁ¿Óõ½Öض¨Ïò¼¼Êõ¡£
¡¡¡¡Öض¨Ïò¼¼Êõ¿ÉÒÔ·ÖΪÁ½À࣬һÀàÊÇ¿Í»§¶ËÖض¨Ïò£¬Ò»ÀàÊÇ·þÎñÆ÷¶ËÖض¨Ïò¡£¿Í»§¶ËÖض¨Ïò¿ÉÒÔͨ¹ýÉèÖÃÌض¨µÄHTTPÍ·£¬»òÕßдJavaScript½Å±¾ÊµÏÖ¡£±¾ÎÄÖ÷Ҫ̽ÌÖ·þÎñÆ÷¶ËÖض¨Ïò¼¼ÊõµÄʵÏÖ¡£
¡¡¡¡·þÎñÆ÷¶ËµÄÖض¨ÏòÏà¹ØÀà
¡¡¡¡·þÎñÆ÷¶ËµÄÖض¨Ïò¼¼ÊõÉæ¼°µ½javax.servlet.ServletContext¡¢javax.servlet.RequestDispatcher¡¢javax.servlet.http.ServletRequest¡¢javax.servlet.http.ServletResponseµÈ¼¸¸ö½Ó¿Ú¡£
¡¡¡¡·þÎñÆ÷¶ËµÄÖض¨Ïò·½Ê½
¡¡¡¡·þÎñÆ÷¶ËµÄÖض¨Ïò¿ÉÒÔÓÐÁ½ÖÖ·½Ê½£¬Ò»ÊÇʹÓÃHttpServletResponseµÄsendRedirect()·½·¨£¬Ò»ÊÇʹÓÃRequestDispatcherµÄforward()·½·¨¡£ÏÂÃæ¶ÔÕâÁ½ÖÖ·½Ê½½øÐнéÉÜ¡£
¡¡¡¡HttpServletResponse.sendRedirect()·½·¨
¡¡¡¡HttpServletResponse½Ó¿Ú¶¨ÒåÁË¿ÉÓÃÓÚתÏòµÄsendRedirect()·½·¨¡£´úÂëÈçÏ£º
¡¡¡¡public void sendRedirect(java.lang.String location)throws java.io.IOException
¡¡¡¡Õâ¸ö·½·¨½«ÏìÓ¦¶¨Ïòµ½²ÎÊýlocationÖ¸¶¨µÄ¡¢ÐµÄURL¡£location¿ÉÒÔÊÇÒ»¸ö¾ø¶ÔµÄURL£¬Èçresponse.sendRedirect("http://java.sun.com")Ò²¿ÉÒÔʹÓÃÏà¶ÔµÄURL¡£Èç¹ûlocationÒÔ“/”¿ªÍ·£¬ÔòÈÝÆ÷ÈÏΪÏà¶ÔÓÚµ±Ç°WebÓ¦Óõĸù£¬·ñÔò£¬ÈÝÆ÷½«½âÎöΪÏà¶ÔÓÚµ±Ç°ÇëÇóµÄURL¡£ÕâÖÖÖض¨ÏòµÄ·½·¨£¬½«µ¼Ö¿ͻ§¶Ëä¯ÀÀÆ÷µÄÇëÇóURLÌøת¡£´Óä¯ÀÀÆ÷ÖеĵØÖ·À¸ÖпÉÒÔ¿´µ½ÐµÄURLµØÖ·£¬×÷ÓÃÀàËÆÓÚÉÏÃæÉèÖÃHTTPÏìӦͷÐÅÏ¢µÄʵÏÖ¡£
¡¡¡¡RequestDispatcher.forward()·½·¨
¡¡¡¡RequestDispatcherÊÇÒ»¸öWeb×ÊÔ´µÄ°ü×°Æ÷£¬¿ÉÒÔÓÃÀ´°Ñµ±Ç°request´«µÝµ½¸Ã×ÊÔ´£¬»òÕß°ÑеÄ×ÊÔ´°üÀ¨µ½µ±Ç°ÏìÓ¦ÖС£RequestDispatcher½Ó¿ÚÖж¨ÒåÁËÁ½¸ö·½·¨£¬²Î¼ûÈçÏ´úÂ룺
¡¡¡¡public interface RequestDispatcher {
¡¡¡¡¡¡void forward(ServletRequest request, ServletResponse response);
¡¡¡¡¡¡void include(ServletRequest request, ServletResponse response);
¡¡¡¡}
¡¡¡¡forward()·½·¨½«µ±Ç°µÄrequestºÍresponseÖض¨Ïòµ½¸ÃRequestDispacherÖ¸¶¨µÄ×ÊÔ´¡£ÕâÔÚʵ¼ÊÏîÄ¿ÖдóÁ¿Ê¹Óã¬ÒòΪÍê³ÉÒ»¸öÒµÎñ²Ù×÷ÍùÍùÐèÒª¿çÔ½¶à¸ö²½Ö裬ÿһ²½ÖèÍê³ÉÏàÓ¦µÄ´¦Àíºó£¬×ªÏòµ½ÏÂÒ»¸ö²½Öè¡£±ÈÈ磬ͨ³£
Ïà¹ØÎĵµ£º
JSPÖеÄÌøת£º
(1). forward()·½·¨
ʹÓõ½javax.servlet.RequestDispatcherÀà
RequestDispatcher rd = getServletContext().getRequestDispatcher("url");
rd.forward(requestVar,requestVar); //´«µÝservletµÄÈë¿Ú²ÎÊý
/*forwardº¯ÊýÒѾ°ÑÔÒ³ÃæµÄrequest,response¶ÔÏó´«ÈëеÄÒ³Ã棬Òò´ËÕâо ......
<%@ page contentType="text/html;charset=GBK"%>
<div id="divDisable" style="display: none;width:expression(document.body.offsetWidth); height:100%; z-index: 1000; position: absolute;left: 0px; top: 0px;filter:alpha(opacity=50); background-color:White">
</div>
<div id="divWaiti ......
ÏÈsunÌá³öµÄÊÇServletÌåϵ£¬Õâ¸öÌåϵʹµÃʹÓÃJAVAµÄ³ÌÐòÔ±Ò²ÄÜ¿ª·¢»ùÓÚB/S¼Ü¹¹µÄWEBÓ¦ÓóÌÐò£¬Ê¹ÓÃServletÀཫHTTPÇëÇóºÍÏìÓ¦·â×°ÔÚ±ê×¼JAVAÀàÖÐÀ´ÊµÏÖ¸÷ÖÖWEBÓ¦Ó÷½°¸¡£
Ëæ×Å´óÁ¿µÄB/S¼Ü¹¹³ÌÐò¿ª·¢³öÀ´ÒÔºó£¬ÈËÃÇ·¢ÏÖServletÀàµÄ±àдÊǷdz£·±ËöµÄ£¬Ö÷Òª¼¯ÖÐÔÚ¼¸¸öÎÊÌâÉÏ£ºÊ×ÏÈÓдóÁ¿ÈßÓà´úÂ룬ÕâЩ´úÂëÔÚÿ¸öservletÀàÖж ......