在httpservlet请求中获取路径参数的任何方法 [英] Any way to get the path parameters in httpservlet request
本文介绍了在httpservlet请求中获取路径参数的任何方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经实施了休息服务.
I have rest service implemented.
我正在尝试在过滤器中获取请求的路径参数.
I am trying to get the path parameters of the the request in filter.
我的请求是
/api/test/{id1}/{status}
/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,则可以访问path参数. -RS请求过滤器:
There's no other way to do it in a ServletFilter other than trying to parse the URI yourself, but you can access the path parameters if you decide to use a JAX-RS request filter:
@Provider
public class PathParamterFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext request) throws IOException {
MultivaluedMap<String, String> pathParameters = request.getUriInfo().getPathParameters();
pathParameters.get("status");
....
}
}
这篇关于在httpservlet请求中获取路径参数的任何方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文