zoukankan      html  css  js  c++  java
  • 路径问题

    转发和重定向的URLString前有加 / 为绝对路径 反之为相对路径

    3.1绝对路径
    1、重定向的 / 表示:http://服务器ip:端口/

    response.sendRedirect("/Manager/index.jsp")
    1
    生成的地址:web服务器本身地址+参数生成完整的URL 即:http://localhost:8080/Manager/index.jsp

    2、请求转发的 / 表示:http://服务器ip:端口/项目名

    request.getRequestDispatcher("/index.jsp").forward(request, response);
    1
    生成的地址:http://localhost:8080/项目名/index.jsp

    重定向是浏览器发来的,只知道发到某个服务器,但是不知道发到服务器的哪个project,所以需要自己用代码声明; 而请求转发是服务器某个project内部的转发,转来转去都是在某个project内部,所以不需要手动声明项目名。

    3.2 相对路径

    假设通过表单请求指定的Url资源 action="LoginServlet"
    则表单生成的请求地址为:http://localhost:8080/项目名/LoginServlet

    1、请求重定向:response.sendRedirect("Manager/index.jsp")
    生成相对路径:http://localhost:8080/项目名/Manager/index.jsp
    2、请求转发:相对路径情况下生成的完整URL与重定向方法相同。

  • 相关阅读:
    ssh: connect to host port 22: Connection refused
    mysql安装出现 conflicts with mysql*的解决办法
    Linux 搭建互信后,仍需要密码验证
    正则表达式的小技巧
    基础的正则表达式与re模块(2)
    包的导入
    import模块
    模块的导入
    logging 模块
    hashlib 模块
  • 原文地址:https://www.cnblogs.com/liujie-e2/p/12735874.html
Copyright © 2011-2022 走看看