1

如果我有一个 tomcat 应用程序(例如,我们称之为测试)。如何在 Tomcat 名称之后捕获字符串的 URI 部分?

http://localhost:8080/Testing/app/d/123/
request.getRequestURL().toString();   # returns http://localhost:8080/Testing/app/d/123/
request.getRequestURI();              # returns /Testing/app/d/123/

在生产环境中,Tomcat 应用程序名称(Testing)显然不会出现。我想捕获 URL 的特定部分,前 2 个正斜杠之间的数据将很重要。如果不指定通过替换来删除 /Testing/ 部分,有没有办法在测试后仅自动返回 URL 的部分?

4

1 回答 1

1

已编辑

尝试:

request.getPathInfo();

它将为您提供 url 的一部分,而没有安装应用程序的服务器地址、端口和上下文。

于 2013-07-24T05:07:54.963 回答