Web资源路径

来源:互联网 发布:银泰百货淘宝是正品吗 编辑:程序博客网 时间:2024/06/05 23:44

1.在浏览器使用,相对于主机,要加web应用目录

<a href="/web1/index.html">     <img src="/web1/index.html"><form action="/web1/index.html">response.setHeader("Location","/web1/index.html");response.setHeader("refresh","3;url=/web1/index.html");response.sendRedirect("/web1/index.html");

2.在服务器使用,相对于web应用,不加web应用目录

request.getRequestDispatcher("/index.jsp").forward();request.getRequestDispatcher("/index.jsp").include();

3.相对于当前web应用目录

servletContext.getRealPath("/");

4.相对于类加载目录的路径, ../../表示类加载目录的上两级目录

classLoader.getResource("../../index.html");

5.相对于java虚拟机启动目录

new File("index.html");new InputStream("index.html");

GitHub博客:http://lioil.win/2017/01/20/Web-URL.html
Coding博客:http://c.lioil.win/2017/01/20/Web-URL.html

0 0