一、在 web.xml 中。
??? 如配置的一个Servlet:
<servlet> <description></description> <display-name>DoLogin</display-name> <servlet-name>DoLogin</servlet-name> <servlet-class>wuyechun.myweb.servlet.DoLogin</servlet-class> </servlet> <servlet-mapping> <servlet-name>DoLogin</servlet-name> <url-pattern>/DoLogin</url-pattern> </servlet-mapping>
??
注:?"/"代表的为工程根目录,“http://localhost:8080/myweb”?? 只要浏览器地址为“http://localhost:8080/myweb/DoLogin”即可访问DoLogin。
?
二、在servlet中。
?如:http://localhost:8080/MyWeb/DoLogin ,它所在的路径为 http://localhost:8080/MyWeb/ 。
当它访问jsp页面,如:http://localhost:8081/MyWeb//jsp/admin/adminIndex.jsp?
1)以forward方式使用的"/"代表的为:?? http://localhost:8081/MyWeb/? ,则有
???? response.sendRedirect("/MyWeb/jsp/admin/adminIndex.jsp");
2)以sendRedirect方式使用的“/”代表的为: http://localhost:8081/? ,则有
??? response.sendRedirect("jsp/admin/adminIndex.jsp")
?
三、在jsp中。
??如:http://localhost:8081/MyWeb/jsp/login.jsp
1)? “/” 代表的为:http://localhost:8080/??????? 可通过 “/MyWeb/DoLogin”访问DoLogin,如提交表单。
2)?? 使用的所谓“相对路径”是以浏览器地址为基准的。 可通过 “../DoLogin”访问DoLogin。
?注:此页面(login.jsp)的地址为http://localhost:8081/MyWeb/jsp/login.jsp? ,在此页面提交表单至Servlet即DoLogin.java 时,可采用的方式有两种,1)? “/" +工程名+sevelet名,即:/MyWeb/DoLogin? ?2)相对路径,"../" 代表本jsp页面的上层目录,即 http://localhost:8081/MyWeb ?,则访问方式为: ../DoLogin