路径 1、项目web.xml中Servlet的映射路径<url-pattern>路径 -- 要么以“*”开关,要么为“/”开头 2、转发和包含路径 > *****以“/”开头:相对当前项目路径,例如:http://localhost:8080/项目名/ request.getRequestdispacher("/BServlet").for...(); > 不以“/”开头:相对当前Servlet路径。 request.getRequestdispacher("/BServlet").for...();, 假如当前Servlet是:http://localhost:8080/项目名/servlet/AServlet, 就是http://localhost:8080/项目名/servlet/BServlet 3、重定向路径(客户端路径) > 以“/”开头:相对当前主机,例如:http://localhost:8080/, 所以需要自己手动添加项目名, 例如;response.sendRedirect("/day10_1/Bservlet"); 4、页面中超链接和表单路径 > 与重定向相同,都是客户端路径!需要添加项目名 > <form action="/day10_1/AServlet"> > <a href="/day10_/AServlet"> > <a href="AServlet">,如果不以“/”开头,那么相对当前页面所在路径。 如果是http://localhost:8080/day10_1/html/form.html。 即:http://localhost:8080/day10_1/html/ASevlet > *****建立使用以“/”开头的路径,即绝对路径! 5、ServletContext获取资源路径 > 相对当前项目目录,即当然index.jsp所在目录 6、ClassLoader获取资源路径 > 相对classes目录 7、Class获取资源路径 > 以“/”开头相对classes目录 > 不以“/”开头相对当前.class文件所在目录。
JavaWeb项目路径详解
猜你喜欢
转载自blog.csdn.net/weixin_42472048/article/details/81701729
今日推荐
周排行