【问题标题】:Java Servlet. Catch full OData URL [duplicate]Java 小服务程序。捕获完整的 OData URL [重复]
【发布时间】:2021-02-27 17:23:49
【问题描述】:

我正在尝试使用 WebServlet 在 Java 中捕获 OData 调用。

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/someservice/UserSet")
public class UserSetServlet extends HttpServlet {

@Override
    protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {

        //some functionality
   }
}

当我简单地调用“http://somdomain.com/someservice/UserSet”时,我会开始服务,但是当我调用“http://somdomain.com/someservice/UserSet("SOME_ID")”时,然后我收到 404,找不到该服务

有人知道我可以如何配置 Servlet 以捕获整个 OData 请求吗?

非常感谢!

【问题讨论】:

  • 你不能将SOME_ID 作为查询参数传递,例如http://somdomain.com/someservice/UserSet?id=SOME_ID
  • 不,这是标准的 OData 过滤格式,用于按 ID 选择
  • servlet 规范及其衍生产品,例如JAX-RS,不支持这种 URL。 JAX-RS 在路径中接受正则表达式,但我不知道它在多大程度上涵盖了 OData URL 规范。您可以做几件事:(a) 放弃 OData 的 URL 规范并使用“正常”查询/路径参数 (b) 编写一个 servlet(或 JAX-RS)过滤器来转换 URI 并在内部转发到使用“ normal" 查询/路径参数 (c) 搜索为您执行此操作的现有框架。

标签: java servlets odata


【解决方案1】:

感谢所有答案。解决方案 - 无论如何。我开始迁移到 Spring Framework。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-23
    • 2020-03-27
    • 2019-11-26
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 2010-09-16
    • 2012-10-04
    相关资源
    最近更新 更多