[英]Retrieving the REST URL pattern from a servlet filter
I have created a rest service with the following url pattern 我已使用以下网址格式创建了一个休息服务
/author/{authorId}/book/{bookId}
In run time I can access the service with the following path 在运行时,我可以通过以下路径访问服务
/author/1234/book/1001
Now I have a ServletFilter
defined. 现在,我定义了一个ServletFilter
。 Every request to access the url/author/1234/book/1001
is hitting the filter too. 访问url/author/1234/book/1001
每个请求也都在过滤器中。 In this filter how can I find the url pattern of the incoming request ie, /author/{authorId}/book/{bookId}
. 在此过滤器中,我如何找到传入请求的url模式,即/author/{authorId}/book/{bookId}
。
Regards -Albin 问候-阿尔宾
first find the real path of the request. 首先找到请求的真实路径。 that is the requested_uri - context_path 那是requested_uri-context_path
String uri = req.getRequestURI();
String context = req.getContextPath();
String realPath = uri.substring(context.length());
then use regex to extract authorId and bookId 然后使用正则表达式提取authorId和bookId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.