冰楓逸范
          Victory won’t come to me unless I go to it. 勝利是不會向我走來的,我必須自己走向勝利。
          在JSP中,跳轉(zhuǎn)頁面有兩種方式:
          1.forward跳轉(zhuǎn):
          <jsp:forward?page="跳轉(zhuǎn)頁面地址"?/>
          2.response跳轉(zhuǎn):
          response.sendRedirect("跳轉(zhuǎn)頁面地址");

          兩種跳轉(zhuǎn)的區(qū)別如下:

          1.forward跳轉(zhuǎn):
          ??a.服務(wù)器端跳轉(zhuǎn),地址欄不改變;
          ??b.執(zhí)行到跳轉(zhuǎn)語句后馬上無條件跳轉(zhuǎn),之后的代碼不再執(zhí)行(跳轉(zhuǎn)之前一定要釋放全部資源);
          ??c.request設(shè)置的屬性在跳轉(zhuǎn)后的頁面仍可以使用;
          ??d.使用<jsp:param?name="參數(shù)名"?value="參數(shù)值"?/>傳遞參數(shù)。

          2.response跳轉(zhuǎn):
          ??a.客戶端跳轉(zhuǎn),地址欄改變;
          ??b.所有代碼執(zhí)行完畢后跳轉(zhuǎn);
          ??c.跳轉(zhuǎn)后的頁面不能使用上一個頁面的request屬性;
          ??d.使用地址重寫傳遞參數(shù)(response.sendRedirect("URL?參數(shù)名=參數(shù)值"))。

          示例:?? forward.jsp
          ?1?<%@?page?contentType?=?"text/html;?charset?=?gb2312"%>
          ?2?<%
          ?3?????request.setCharacterEncoding("gb2312");
          ?4?%>
          ?5?
          ?6?<html>
          ?7?????<head>
          ?8?????????<title>?Forward.jsp?</title>
          ?9?????</head>
          10?
          11?????<body>
          12?????????<jsp:forward?page?=?"jump.jsp"?/>
          13?????</body>
          14?</html>
          ???
          ?????????response.jsp
          ?1?<%@?page?contentType?=?"text/html;?charset?=?gb2312"%>
          ?2?<%
          ?3?????request.setCharacterEncoding("gb2312");
          ?4?%>
          ?5?
          ?6?<html>
          ?7?????<head>
          ?8?????????<title>?跳轉(zhuǎn)頁面?</title>
          ?9?????</head>
          10?
          11?????<body>
          12?????<%
          13?????????response.sendRedirect("jump.jsp");
          14?????%>
          15?????</body>
          16?</html>

          ????????jump.jsp
          1?<html>
          2?????<head>
          3?????????<title>?跳轉(zhuǎn)頁面?</title>
          4?????</head>
          5?<body>
          6?????<h1>?Hello?Word!!!?</h1>
          7?</body>
          8?</html>

          可以發(fā)現(xiàn)使用forward跳轉(zhuǎn),地址欄的url沒變;而使用response.sendRedirect()地址欄的url有變.
          posted on 2008-04-06 13:18 冰楓逸范 閱讀(989) 評論(0)  編輯  收藏 所屬分類: JSP/Servlet
          主站蜘蛛池模板: 磐安县| 永城市| 连平县| 庆城县| 广元市| 广水市| 宁城县| 商丘市| 苗栗县| 高要市| 高陵县| 宜兴市| 潮安县| 雷波县| 当阳市| 云阳县| 新竹县| 青海省| 司法| 二连浩特市| 罗江县| 林州市| 乐安县| 和顺县| 延安市| 黔东| 定边县| 云阳县| 公安县| 高台县| 都匀市| 安泽县| 腾冲县| 巴林右旗| 武定县| 石泉县| 离岛区| 大田县| 长葛市| 黄冈市| 新化县|