servlet url-pattern /和/ *之间的区别

时间:2014-04-04 10:21:42

标签: servlets web.xml url-pattern

有什么区别:

<servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
</servlet-mapping>

<servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
</servlet-mapping>

2 个答案:

答案 0 :(得分:2)

/仅匹配root即。 http://yourserver/webapplication//*会匹配所有针对您的应用http://yourserver/webapplication/以及http://yourserver/webapplication/any/path/you/want

的请求

答案 1 :(得分:-1)

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

http://server.local/your-application/映射到调度程序servlet

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

http://server.local/your-application/%ANYTHING%映射到调度程序servlet