ÎåÖÖJSPÒ³ÃæÌøת·½·¨Ïê½â(2)
3. £¼jsp:forward page="" /£¾
ËüµÄµ×²ã²¿·ÖÊÇÓÉRequestDispatcherÀ´ÊµÏֵģ¬Òò´ËËü´øÓÐRequestDispatcher.forward()·½·¨µÄÓ¡¼Ç¡£
Èç¹ûÔÚ֮ǰÓкܶàÊä³ö,Ç°ÃæµÄÊä³öÒÑʹ»º³åÇøÂú,½«×Ô¶¯Êä³öµ½¿Í»§¶Ë,ÄÇô¸ÃÓï¾ä½«²»Æð×÷ÓÃ,ÕâÒ»µãÓ¦¸ÃÌرð×¢Òâ¡£
ÁíÍâҪעÒ⣺Ëü²»Äܸıää¯ÀÀÆ÷µØÖ·£¬Ë¢ÐµĻ°»áµ¼ÖÂÖظ´Ìá½»
4. ÐÞ¸ÄHTTP headerµÄLocationÊôÐÔÀ´Öض¨Ïò
ͨ¹ýÉèÖÃÖ±½ÓÐ޸ĵØÖ·À¸À´ÊµÏÖÒ³ÃæµÄÖض¨Ïò¡£
jspÎļþ´úÂëÈçÏ£º
£¼%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn = "/newpath/jsa.jsp";
response.setHeader("Location",newLocn);
%£¾
5. JSPÖÐʵÏÖÔÚijҳÃæÍ£ÁôÈô¸ÉÃëºó,×Ô¶¯Öض¨Ïòµ½ÁíÒ»Ò³Ãæ
ÔÚhtmlÎļþÖУ¬ÏÂÃæµÄ´úÂ룺
£¼meta http-equiv="refresh" content="300; url=target.jsp"£¾
ËüµÄº¬Ò壺ÔÚ5·ÖÖÓÖ®ºóÕýÔÚä¯ÀÀµÄÒ³Ã潫»á×Ô¶¯±äΪtarget.htmlÕâÒ»Ò³¡£´úÂëÖÐ300ΪˢеÄÑÓ³Ùʱ¼ä£¬ÒÔÃëΪµ¥Î»¡£targer.htmlΪÄãÏëתÏòµÄÄ¿±êÒ³,ÈôΪ±¾Ò³ÔòΪ×Ô¶¯Ë¢Ð±¾Ò³¡£
ÓÉÉÏ¿ÉÖª£¬¿ÉÒÔͨ¹ýsetHeaderÀ´ÊµÏÖijҳÃæÍ£ÁôÈô¸ÉÃëºó,×Ô¶¯Öض¨Ïòµ½ÁíÒ»Ò³Ãæ¡£
¹Ø¼ü´úÂ룺
String content=stayTime+";URL="+URL;
response.setHeader("REFRESH",content);
Ïà¹ØÎĵµ£º
1 ±ê¼Ç´¦Àí³ÌÐòÀà
´¦ÀíÀà¼Ì³ÐTagSupportÀಢÖØÔØdoStartTag()·½·¨,
Ôڸ÷½·¨ÖÐʹÓÃout.print();Êä³öÐèÒªµÄÊý¾Ýµ½Ê¹Óñ¾±êÇ©µÄjspÒ³Ãæ
package cn.xxx;
public class DateTag extends TagSupport {
private static final long serialVersionUID = 1L;
public int doStartTag() thr ......
ÏÈsunÌá³öµÄÊÇServletÌåϵ£¬Õâ¸öÌåϵʹµÃʹÓÃJAVAµÄ³ÌÐòÔ±Ò²ÄÜ¿ª·¢»ùÓÚB/S¼Ü¹¹µÄWEBÓ¦ÓóÌÐò£¬Ê¹ÓÃServletÀཫHTTPÇëÇóºÍÏìÓ¦·â×°ÔÚ±ê×¼JAVAÀàÖÐÀ´ÊµÏÖ¸÷ÖÖWEBÓ¦Ó÷½°¸¡£
Ëæ×Å´óÁ¿µÄB/S¼Ü¹¹³ÌÐò¿ª·¢³öÀ´ÒÔºó£¬ÈËÃÇ·¢ÏÖServletÀàµÄ±àдÊǷdz£·±ËöµÄ£¬Ö÷Òª¼¯ÖÐÔÚ¼¸¸öÎÊÌâÉÏ£ºÊ×ÏÈÓдóÁ¿ÈßÓà´úÂ룬ÕâЩ´úÂëÔÚÿ¸öservletÀàÖж ......
Èç¹ûweb.xmlÀïÃæµÄ<web-app>ÊÇversion="2.4"£¬ÄÇô¾ÍÒªÔÚ<jsp-property-group>ÀïÉèÖá£Èç¹ûversion="2.5"¾Í²»ÐèÒª¡£
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/javae ......
Ò»£¬jsp³öÏֵĵÄÔÒò
¿´Á½¶Î´úÂëµÄ¶Ô±È
1 servletʵÏÖ
public class Welcome extends HttpServlet {
int num = 1;
public void doGet(HttpServletRequest request,
&nbs ......
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()ÎÞ·¨Öض¨ÏòÖÁÓÐframeµ ......