• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
星空摇曳
博客园    首页    新随笔    联系   管理    订阅  订阅
几种页面跳转方法

页面跳转方式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一直可以进行传递--重定向。
 
posted on 2019-06-04 16:59  星空摇曳  阅读(3619)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3