如何从 Restlet 读取上下文参数?

发布于 2024-07-18 04:02:20 字数 248 浏览 2 评论 0原文

使用Restlet时,如何读取通过web.xml传入的配置参数? 对于 servlet,可以使用 context-param。 如何从 Restlet 中读取上下文参数?

When using Restlets, how can I read configuration parameters passed in through web.xml? With servlets, context-param can be used. How do I read context parameters from within a Restlet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新人笑 2024-07-25 04:02:20

来自邮件列表

初始化参数可在

在 web.xml 中:

  <context-param>
    <param-name>my.context.param</param-name>
    <param-value>Hello World</param-value>
  </context-param>

在 Restlet 的代表方法中,使用:

// => "Hello World"
String result = 
  getApplication().getContext().getParameters().getFirstValue("my.context.param");

From the mailing list:

the init parameters are available in the application's context:
getApplication().get​Context().getParamet​ers().

In web.xml:

  <context-param>
    <param-name>my.context.param</param-name>
    <param-value>Hello World</param-value>
  </context-param>

In a Restlet's represent method, use:

// => "Hello World"
String result = 
  getApplication().getContext().getParameters().getFirstValue("my.context.param");
别靠近我心 2024-07-25 04:02:20

ServerServlet 将来自 servletConfigservletContext 的所有 init 参数添加到应用程序上下文中。

因此,根据您的需要,您可以检查 ServerServlet 的源代码,并以相同的方式读取配置参数,或者只是从您的 Restlet 或 Restlet 的应用程序上下文中获取值。

ServerServlet adds all the init parameters from both the servletConfig and from the servletContext to the application context.

So depending on your need, you could either examine the source code for ServerServlet, and read the configuration parameters in the same way, or simply obtain the values from your restlet, or your restlet's application's context.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文