代码之家  ›  专栏  ›  技术社区  ›  Rich Apodaca

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

  •  2
  • Rich Apodaca  · 技术社区  · 17 年前

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

    2 回复  |  直到 17 年前
        1
  •  3
  •   Rich Apodaca    17 年前

    mailing list :

    init参数在 application's context : getApplication().get__context().getParamete_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
  •  1
  •   Stephen Denne    17 年前

    ServerServlet 添加来自 servletConfig servletContext 应用程序上下文。

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