首页 > 其他分享 >Response-路径-相对路径、绝对路径

Response-路径-相对路径、绝对路径

时间:2022-11-29 19:37:10浏览次数:37  
标签:http responseDemo2 request 绝对路径 相对路径 import Response

Response-路径-相对路径

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

    如:./index.html

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

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

    ./:当前目录

    ../:后退一级目录.

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

    </P>
    <P>
        目标资源:
        http://localhost/day15/responseDemo2

    </P>

    <a href="./responseDemo2">
        responseDemo2
    </a>

    <a href="responseDemo2">
        responseDemo2
    </a>
    <br>
    <hr>


    <h1>绝对路径</h1>

    <a href="/day15/responseDemo2">
        responseDemo2
    </a>


</body>
</html>

 

Response-路径-绝对路径

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

    如:http://localhost/day15/responseDemo2 /day15/responseDemo2

    以/开头的路径

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

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

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

    <a> , <form> 重定向...

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

    转发路径  

package com.example.day_14_response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@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);
    }
}

 

标签:http,responseDemo2,request,绝对路径,相对路径,import,Response
From: https://www.cnblogs.com/yuzong/p/16936447.html

相关文章