JavaWeb项目中路径的问题 曾经终败给现在 2021-06-24 16:11 409阅读 0赞 * web.xml中<url-pattern>路径(即servlet路径): 要么以“\*”开头或者结尾,要么为“/"开头 * 转发和包含路径 以"/”开头:相对当前项目路径,例如: [http://localhost:8080/项目名/][http_localhost_8080] 不以“/"开头:相对当前Servlet路径。 * 重定向路径(客户端路径) 以/”开头:相对当前主机,例如: [http://localhost:8080/][http_localhost_8080 1] ,所以需要自己手动添加项目名。 * 页面中超链接和表单路径 与重定向相同,都是客户端路径!需要添加项目名 * servletContext获取资源路径 相对当前项目目录,即当然index.jsp所在目录 * ClassLoader获取资源路径 相对classes目录 * Class获取资源路径 以“/”开头相对classes目录 不以“/"开头相对当前.class文件所在目录。 [http_localhost_8080]: http://localhost:8080/%E9%A1%B9%E7%9B%AE%E5%90%8D/ [http_localhost_8080 1]: http://localhost:8080/
还没有评论,来说两句吧...