首页 > 其他分享 >Response_路径_相对路径以及绝对路径

Response_路径_相对路径以及绝对路径

时间:2022-12-07 14:57:09浏览次数:42  
标签:http 路径 request 绝对路径 html 相对路径 Response 资源

Response_路径_相对路径以及绝对路径

1.相对路径:通过相对路径不可以确定唯一资源

  如:./index.html

  不以/开头,以.开头路径

 

规则:找到当前资源和目标资源之间的相对位置关系

  ./当前路径

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>找到当前资源和目标资源的相对位置关系</h1>
    <p>
        当前资源:location.html
        http://localhost/location.html
    </p>
    <p>
        目标资源:
        http://localhost/responseDemo2
    </p>

    <a href="./responseDemo2">
        responseDemo02
    </a>
</body>
</html>

  ../:回退以及目录

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>找到当前资源和目标资源的相对位置关系</h1>
    <p>
        当前资源:location2.html
        http://localhost/htmls/location2.html
    </p>
    <p>
        目标资源:
        http://localhost/responseDemo2
    </p>

    <a href="../responseDemo2">
        responseDemo02
    </a>
</body>
</html>

 

 

2绝对路径:通过绝对路径可以确定唯一资源

  如:http://localhost/responseDemo2    

  以/开头路径

html页面:

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <h1>绝对路径</h1>
    <a href="/requestDemo2">
        requestDemo2
    </a>
</body>
</html>
复制代码

 

内部使用:

复制代码
@WebServlet("/responseDemo3")
public class ResponseDemo3 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //转发
        request.getRequestDispatcher("/responseDemo2").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
复制代码

 

 

规则:判断定义的路径是给谁用的?判断请求将来从哪发出

  给客户端浏览器使用:需要加虚拟目录(项目的访问路径)

    建议虚拟目录动态获取:request.getContextPath()

 

  给服务器使用:不需要加虚拟目录

 

标签:http,路径,request,绝对路径,html,相对路径,Response,资源
From: https://www.cnblogs.com/qihaokuan/p/16963060.html

相关文章

  • 006.封装ResponseUtils工具类
    1.封装ResponseUtils(对标准的Code、Message进行设置)packagecom.imooc.oa.utils;importcom.fasterxml.jackson.annotation.JsonInclude;importcom.fasterxml.jackson......
  • Response_重定向的代码实现以及特点
    Response_重定向的代码实现以及特点重定向:资源跳转的方式@WebServlet(name="ResponseDemo1",value="/ResponseDemo1")publicclassResponseDemo1extendsHttpSe......
  • HTTP_响应消息_响应头和Response_功能介绍
    HTTP_响应消息_响应头格式:头名称:值常见的响应头:1.Content-Type:服务器告诉客户端本次响应体数据格式以及编码格式2.Content-disposition:服务器告诉客户端以什么......
  • Python (os模块 相对路径使用方法)
    导入os模块importos返回路径path1=os.path.abspath(__file__)print(path1)#当前文件的绝对路径game_folder=os.path.dirname(__file__)print(game_folder)#当前文件的相......
  • Response.iter_content和r.raw
    普通情况可以用r.raw,在初始请求中设置stream=True,来获取服务器的原始套接字响应r=requests.get(url,stream=True)r.raw.read(10)当流下载时,用Response.iter_c......
  • Response-案例验证码-代码实现、点击切换
    Response-验证码-代码实现packagecom.example.day_14_response;importjavax.imageio.ImageIO;importjavax.servlet.ServletException;importjavax.servlet.Servl......
  • Response-输出字符数据、输出字节数据
    Response-输出字符数据服务器输出字符数据到浏览器步骤:1.获取字符输出流2.输出数据注意:乱码问题......
  • Response-路径-相对路径、绝对路径
    Response-路径-相对路径相对路径:通过相对路径不可以确定唯一资源如:./index.html不以/开头,以.开头路径规则:找到当前资源和目标资源之间的相对......
  • Response-重定向代码实现、特点
    Response-重定向-代码实现案例: 1.完成重定向 重定向:资源跳转的方式 代码实现: 设置状态码为302 ......
  • HTTP-响应消息-响应头、Response-功能介绍
    HTTP-响应消息-响应头响应头: 1.格式:头名称:值 2.常见的响应头: 1.Content-Type:服务器告诉客户端本次响应体数据格式以及编码......