国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

jsp中forword和sendRedirect的區別

2024-09-05 00:19:15
字體:
來源:轉載
供稿:網友


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的jsp文件,可以重定向至有frame的html文件,同時forward()無法在后面帶參數傳遞,比如 servlet?name=frank,這樣不行,可以程序內通過response.setattribute("name",name)來傳至下一個頁面.

重定向后瀏覽器地址欄url不變.

例:servlet文件中重定向
code

public void dopost(httpservletrequest request,httpservletresponse response)

       throws servletexception,ioexception

{

       response.setcontenttype("text/html; charset=gb2312");

       servletcontext sc = getservletcontext();

       requestdispatcher rd = null;

       rd = sc.getrequestdispatcher("/index.jsp");

       rd.forward(request, response);
}

2.response.sendredirect()

是在用戶的瀏覽器端工作,sendredirect()可以帶參數傳遞,比如servlet?name=frank傳至下個頁面,同時它可以重定向至不同的主機上,且在瀏覽器地址欄上會出現重定向頁面的url.

sendredirect()可以重定向有frame的jsp文件.

例:servlet文件中重定向
code

public void dopost(httpservletrequest request,httpservletresponse response)

       throws servletexception,ioexception

{

       response.setcontenttype("text/html; charset=gb2312");

       response.sendredirect("/index.jsp");

}

 

 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 垦利县| 延长县| 临夏县| 万载县| 柯坪县| 万州区| 毕节市| 阜阳市| 宣汉县| 九台市| 通海县| 新巴尔虎右旗| 大港区| 新巴尔虎左旗| 上虞市| 抚松县| 外汇| 四会市| 金沙县| 泸州市| 新密市| 平邑县| 库伦旗| 曲阜市| 贵德县| 北辰区| 皋兰县| 侯马市| 通辽市| 清原| 图木舒克市| 临湘市| 新丰县| 全椒县| 交口县| 喜德县| 城固县| 剑川县| 天柱县| 平南县| 波密县|