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

有帮助吗?

解决方案

来自邮件列表

  

init参数可在应用程序的上下文:   。getApplication()得到​上下文()getParamet​ ERS()

在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");

其他提示

ServerServlet servletConfig servletContext 中的所有init参数添加到应用程序上下文中。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top