【问题标题】:How To Read Context Parameters From a Restlet?如何从 Restlet 中读取上下文参数?
【发布时间】:2009-05-01 04:17:44
【问题描述】:

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

【问题讨论】:

    标签: java servlets restlet


    【解决方案1】:

    来自mailing list

    init 参数在application's context 中可用: getApplication().get​Context().getParamets​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");
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2014-03-16
        • 1970-01-01
        • 1970-01-01
        • 2010-11-06
        • 2011-10-07
        • 2011-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多