gpt4 book ai didi

rest - 在httpservlet请求中获取路径参数的任何方法

转载 作者:行者123 更新时间:2023-12-02 11:25:28 24 4
gpt4 key购买 nike

我已实现休息服务。

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

我的要求是

/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");
....
}
}

关于rest - 在httpservlet请求中获取路径参数的任何方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22199830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com