在httpservlet请求中获取路径参数的任何方式 [英] Any way to get the path parameters in httpservlet request

查看:28
本文介绍了在httpservlet请求中获取路径参数的任何方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实施了休息服务.

I have rest service implemented.

我正在尝试在过滤器中获取请求的路径参数.

I am trying to get the path parameters of the the request in filter.

我的要求是

/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 请求过滤器:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆