How are Servlet paths mapped?

补充点基础知识. Path mappings are used to map a URI to a contexts, handlers and servlets.

The following types of mapping are supported and applied in the order presented.

Absolute Mapping
Path Spec:      /path

Will match: /path path=/path info=<null>

Will not match: / /path/ /path/info /path/info.jsp /other
Prefix Mapping
Path Spec:      /path/*

Will match: /path path=/path info=<null> /path/ path=/path info=/ /path/info path=/path info=/info /path/info.jsp path=/path info=/info.jsp

Will not match: / /other
Suffix Mapping
Path Spec:      *.jsp

Will match: /path/info.jsp path=info=/path/info.jsp

Will not match: / /path /path/ /path/info /other
Default Mapping
Path Spec:      /

Will match: / path= info=/ /path path= info=/path /path/ path= info=/path/ /path/info path= info=/path/info /path/info.jsp path= info=/path/info.jsp /other path= info=/other

Will not match:

Typical examples

Context and Servlet with path
  Context Path Spec :    /context/*  Servlet Path Spec :    /servlet/*

URI ContextPath ServletPath PathInfo ========================================================= /context/servlet /context /servlet null /context/servlet/ /context /servlet / /context/servlet/x /context /servlet /x


Default Context
  Context Path Spec :    /  Servlet Path Spec :    /servlet/*

URI ContextPath ServletPath PathInfo ========================================================= /servlet "" /servlet null /servlet/ "" /servlet / /servlet/x "" /servlet /x


Context and Suffix Servlet
  Context Path Spec :    /context/*  Servlet Path Spec :    *.txt

URI ContextPath ServletPath PathInfo ========================================================= /context/xxx.txt /context "" /xxx.txt


Context and Default Servlet
  Context Path Spec :    /context/*  Servlet Path Spec :    /

URI ContextPath ServletPath PathInfo ========================================================= /context/xxx /context "" /xxx


Default Context and Servlet
  Context Path Spec :    /  Servlet Path Spec :    /

URI ContextPath ServletPath PathInfo ========================================================= /xxx "" "" /xxx
来自:http://jetty.mortbay.org/jetty/faq?s=500-Servlets&t=Path%20Mapping

你可能感兴趣的:(jsp,servlet)