【发布时间】:2009-05-01 04:17:44
【问题描述】:
使用Restlets时,如何读取通过web.xml传入的配置参数?对于 servlet,可以使用 context-param。如何从 Restlet 中读取上下文参数?
【问题讨论】:
使用Restlets时,如何读取通过web.xml传入的配置参数?对于 servlet,可以使用 context-param。如何从 Restlet 中读取上下文参数?
【问题讨论】:
来自mailing list:
init 参数在application's context 中可用: getApplication().getContext().getParametsers().
在 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 的所有初始化参数添加到应用程序上下文中。
因此,根据您的需要,您可以检查ServerServlet 的源代码,并以相同的方式读取配置参数,或者只是从您的restlet 或您的restlet 应用程序的上下文中获取值。
【讨论】: