配置tomcat5.5的端口为: 8080 ,地址栏为:"http://localhost:8080/WebTest/index.jsp",应用结果如下:
request.getContextPath() : /WebTest
(Returns the portion of the request URI that indicates the context of the request. )
request.getServletPath() : /index.jsp
(Returns the part of this request's URL that calls the servlet. )
request.getRequestURI() : /WebTest/index.jsp
(Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request .)
request.getRequestURL() : http://localhost:8080/WebTest/index.jsp
(Reconstructs the URL the client used to make the request .)
xml配置:
<servlet> <servlet-name>CheckCode</servlet-name> <servlet-class> test.CheckCode </servlet-class> </servlet> <servlet-mapping> <servlet-name>CheckCode</servlet-name> <url-pattern>/checkcode</url-pattern> </servlet-mapping>