假设我有一个 Java 服务器, 我想用它做两个(或更多)不同的 URL 模式:
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/this/exact/path</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/that/prefix/path/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/yet/another/exact/path</url-pattern>
</servlet-mapping>
我的服务会被召唤到任何:
/this/exact/path
/yet/another/exact/path
/that/prefix/path/param1
/that/prefix/path/param2.html
我想知道的是,我怎样才能从我的代码中知道请求被匹配的路径是什么? (即,如果请求是向 /myapp/yet/another/exact/path
提出的,我想获得字符串 /yet/another/exact/path
) 。
最好有人能告诉我该如何做。
我尝试了 string 路径 = req.get truetractorURI ()
但它也返回 /myap 部分 。