客户端和服务端路径问题
1. 客户端路径和服务器端路径
* 客户端路径需要给出应用名称,例如:/day05_1/AServlet
* 服务器端路径无需给出应用名称,例如:/AServlet
2. 客户端路径
1). 页面中都是客户端路径:
* 超链接的href
* 表单的action
* <img>的src
2). 重定向也是客户端路径:response.sendRedirect("/day05_1/BServlet");
//1、不以 / 开头相对路径 、
相对当前页面的路径
//2、 以“ / ”开头,相对主机,与当前 a.html 的主机相同,即最终访问的页面为 http://localhost:8080 /hello2/index.html ;
//3、以这种形式 http://localhost:8080/hello1/pages/a.html写,表示绝对路径
注意事项
3)、因为采用“/”开头,相对主机路径,所以每个项目名一旦改变,就都要修改,所以后天采用 request.getContextPath()获得项目名
3、服务器端路径
1)、 服务器端路径以“ / ”开头:相对当前应用。
2)、 因为路径不以“ / ”开头,所以相对当前应用,即 http://localhost:8080/hello/servlet/ BServlet 。
//2、 以“ / ”开头,相对主机,与当前 a.html 的主机相同,即最终访问的页面为 http://localhost:8080 /hello2/index.html ;
//3、以这种形式 http://localhost:8080/hello1/pages/a.html写,表示绝对路径
注意事项
3)、因为采用“/”开头,相对主机路径,所以每个项目名一旦改变,就都要修改,所以后天采用 request.getContextPath()获得项目名
3、服务器端路径
1)、 服务器端路径以“ / ”开头:相对当前应用。
2)、 因为路径不以“ / ”开头,所以相对当前应用,即 http://localhost:8080/hello/servlet/ BServlet 。