我已实现休息服务。
我正在尝试在过滤器中获取请求的路径参数。
我的要求是
/api/test/{id1}/{status}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
throws IOException, ServletException
{
//Way to get the path parameters id1 and status
}
最佳答案
除了尝试自己解析URI之外,没有其他方法可以在ServletFilter中完成,但是如果您决定使用JAX-RS请求过滤器,则可以访问路径参数:
@Provider
public class PathParamterFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext request) throws IOException {
MultivaluedMap<String, String> pathParameters = request.getUriInfo().getPathParameters();
pathParameters.get("status");
....
}
}