* web.xml中<url-pattern>路径,(相对于项目路径,比如boostore/)
> *****以“/”开头:相对当前项目路径,例如:http://localhost:8080/项目名/ request.getRequestdispacher("/BServlet").for...();
> 以“/”开头:相对当前主机,例如:http://localhost:8080/, 所以需要自己手动添加项目名,例如;response.sendRedirect("/day10_1/Bservlet");
> <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
> 以“/”开头相对classes目录
> 不以“/”开头相对当前.class文件所在目录。
> 要么以“*”开关,要么为“/”开头
> *****以“/”开头:相对当前项目路径,例如:http://localhost:8080/项目名/ request.getRequestdispacher("/BServlet").for...();
> 不以“/”开头:相对当前Servlet路径。 request.getRequestdispacher("/BServlet").for...();,假如当前Servlet是:http://localhost:8080/项目名/servlet/AServlet就是 http ://localhost:8080/项目名/servlet/BServlet
> 以“/”开头:相对当前主机,例如:http://localhost:8080/, 所以需要自己手动添加项目名,例如;response.sendRedirect("/day10_1/Bservlet");
* 页面中超链接和表单路径
> 与重定向相同,都是客户端路径!需要添加项目名> <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
> *****建立使用以“/”开头的路径,即绝对路径!
> 相对当前项目目录,即当然index.jsp所在目录
> 相对classes目录
> 以“/”开头相对classes目录
> 不以“/”开头相对当前.class文件所在目录。
本文详细介绍了Web应用中各种路径配置的使用方法,包括web.xml中的<url-pattern>路径配置、转发和包含路径的区别、重定向路径的使用场景、页面中超链接和表单路径的配置方式、以及ServletContext、ClassLoader和Class获取资源路径的方法。
514

被折叠的 条评论
为什么被折叠?



