Forwarding redirect 绝对路径 相对路径

原文地址:https://www.programmersought.com/article/8728115849/

Forwarding is the same request (requesting the next resource by the server)
Redirect is a multiple request (redirected by the server to the client, the client requests the next resource)
A summary of the sentence: forwarding is a request from the server, the redirect is made by the client

Note: Forwarding and redirecting URLStrings are preceded by plus / for absolute paths and vice versa for relative paths

对于Redirect

  1. Assume that the specified Url resource is requested via the form action="LoginServlet"   

    The request address generated by the form is:Http://localhost:8080/project name/LoginServlet

  2. Redirect to the specified resource below after the servlet processes the request. Parameters can be specified as relative paths or absolute paths or web applications.

    1. relative path: response.sendRedirect("Manager/index.jsp") Generated address: The original request address + parameter generates the complete URL: Http://localhost:8080/project name/Manager/index.jsp                                              

    2. absolute path: response.sendRedirect("/Manager/index.jsp") The generated address: the web server's own address + parameters to generate the complete URL ie: http://localhost:8080/Manager/index.jsp                         

  3. other web application addresses

    The container is directed to the URL: response.sendRedirect(“http://www.baidu.com”) 

对于Forward

Forward to the specified resource below after the servlet processes the request. The parameter can be specified as a relative path or an absolute path.

  1. relative path 
    1. The full URL generated in the case of a relative path is the same as the redirect method.
  2. absolute path 
    1. Absolute path is different from redirection, the container will generate the full URL relative to the root directory of the web application. Generated address: The original request address + parameter generates the complete URL: Http://localhost:8080/project name/Manager/index.jsp Forwarding is the same for both relative and absolute path addresses.
    2.  
  3. ServletContext.getRequestDispatcher(UrlString)The parameter can only be specified as an absolute path, and the resulting full URL is the same as HttpServletRequest.getRequestDispatcher(String).
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值