几种页面跳转方法

页面跳转方式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一直可以进行传递--重定向。
 

猜你喜欢

转载自www.cnblogs.com/zybcn/p/10974598.html