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

          兩種跳轉的區別如下:

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

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

          示例:?? 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>?跳轉頁面?</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>?跳轉頁面?</title>
          4?????</head>
          5?<body>
          6?????<h1>?Hello?Word!!!?</h1>
          7?</body>
          8?</html>

          可以發現使用forward跳轉,地址欄的url沒變;而使用response.sendRedirect()地址欄的url有變.
          posted on 2008-04-06 13:18 冰楓逸范 閱讀(989) 評論(0)  編輯  收藏 所屬分類: JSP/Servlet
          主站蜘蛛池模板: 星座| 长治市| 昌黎县| 永登县| 南投市| 宁陵县| 峡江县| 桑植县| 高安市| 平凉市| 临海市| 临高县| 墨竹工卡县| 桂平市| 浑源县| 清河县| 清水河县| 兴山县| 黔东| 集安市| 福建省| 原阳县| 镇康县| 丹凤县| 永善县| 马关县| 四会市| 凌云县| 莱西市| 台州市| 辽阳市| 泾川县| 扬州市| 太保市| 监利县| 东乌| 东阳市| 成都市| 土默特左旗| 禄劝| 山东省|