国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項超值服

開通VIP
轉(zhuǎn)貼:JSP中兩種跳轉(zhuǎn)與servlet的兩種轉(zhuǎn)向
JSP中兩種跳轉(zhuǎn)與servlet的兩種轉(zhuǎn)向

(一)JSP中兩種跳轉(zhuǎn)

在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有變.

(二)servlet的兩種轉(zhuǎn)向

跳轉(zhuǎn)有兩種方式,重定向與轉(zhuǎn)發(fā)。

重定向可以使用HttpServletResponse對象
如 response.sendRedirect(\"xxx.jsp\"); //參數(shù)為url地址
上面方法如同js的location.href=\"xxx.jsp\";

轉(zhuǎn)發(fā)使用HttpServletRequest對象
request.getRequestDispatcher(\"xxx.jsp\").forward(request, response);
轉(zhuǎn)發(fā)則把請求交給jsp頁來處理

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Jsp&servlet中Dispatcher.forward和response.sendRedirect的區(qū)別 - 新地址_http://hi.baidu.com/snowyvalley - JavaEye技術(shù)網(wǎng)站
jsp/servlet的重定向技術(shù)綜述
jsp中forword和sendRedirect的區(qū)別
request的setAttribute()怎么用的?
java servlet 幾種頁面跳轉(zhuǎn)的方法及傳值
幾種servlet頁面跳轉(zhuǎn)方式。_iechenyb
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服