getServletPath()

来源:互联网 发布:csgo和彩虹六号知乎 编辑:程序博客网 时间:2024/06/05 05:37


http://localhost:8080/myfirstServlet/index.jsp,注,通过index。jsp转到GenerServ的


getContextPath:返回,/myfirstServlet
getRequestURl:返回,/myfirstServlet/servlet/GenerServ


getServletPath


java.lang.String getServletPath()
Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME.

This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.

返回请求URL中调用该servlet的那一部分,这个路径是以"/"开头的,要么包含servlet名,要么包含一个走到该servlet的路径,但是不包含任何额外的路径信息,或者一个查询字符串,如同CGI的变量SCRIPT_NAME,如果这个servlet的请求路径是用“/*”来匹配的,那么这个方法将返回""

附上两篇博文,便于理解:request.getServletPath()和request.getPathInfo()用法

                                          

                                 getContextPath、getServletPath、getRequestURI的区别

0 0
原创粉丝点击