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