幾種頁面跳轉方法


頁面跳轉方式1——herf

  在一些html的文檔中,用herf實現頁面跳轉的比較常見,也很好用。

頁面跳轉方式2——利用表單action

 

<td>
      <form method="post" action="ChangrCount.jsp" id="form1">
              <input type="hidden" name="albumId" value="${item.albumId}" />
              <input style="width:50px;" type="text" name="count" value="${item.count}" id="namecount"/>                                
      </form>
</td>

頁面跳轉方式3——response.sendRedirect("cart.jsp");

esponse.sendRedirect("cart.jsp");的功能是地址重定向(頁面跳轉);     


服務器端進行轉向的4種方法:
1. servletcontext 的 getrequestdispatcher()
路徑必須是相對上下文的絕對路徑
2. servletcontext 的 getnameddispatcher()
3. servletrequest 的 getrequestdispatcher()
可以是相對也可以是絕對
4. servletresponse 的 sendredirect()進行轉向。

 

response.sendredirect(url);  對服務器的響應進行重定向。當server作出響應后,client客戶端的請求的生存周期就終止了。
這個時候再用request.getparameter()或request.getattribute()得到的只能是null。
getservletcontext().getrequestdispatcher(url).forward(request,response);它則可以認為是對client的請求(request)進行傳遞,在server沒有進行響應前,即沒有response一直可以進行傳遞--重定向。
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM