HTTP_路径、HTTP_案例路径_绝地路径

HTTP_路径

路径的写法:

  路径的分类:

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

     如:./index.thml

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

      规则:确定当前资源和目标资源之间的想对应位置关系

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

      如:http//localhost/day15/respon2

      以/开头的路径

 

HTTP_案例路径_绝地路径

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

      如:http//localhost/day15/respon2

      以/开头的路径

   规则:判断定义的路径是给谁用的?

     给客户端浏览器使用的:需要加虚拟目录

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

还可以动态的获取虚拟目录:

  

@WebServlet(value = "/Servlet1")
public class Servlet1 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// 动态虚拟目录
String contextPath = request.getContextPath();
response.sendRedirect(contextPath+"/Servlet2");
}
}

 

 

  

posted @ 2022-08-15 11:12  一位程序袁  阅读(288)  评论(0)    收藏  举报