Was ist der Zweck der ServletContext setInitParameter? Wie kann man es benutzen?

Den Servlet-3.0-Spezifikation, die sagt:

setInitParameter

boolean setInitParameter(java.lang.String name,
                         java.lang.String value)

    Sets the context initialization parameter with the given name and value on this ServletContext.

    Parameters:
        name - the name of the context initialization parameter to set
        value - the value of the context initialization parameter to set 
    Returns:
        true if the context initialization parameter with the given name and value was set successfully on this ServletContext, and false if it was not set because this ServletContext already contains a context initialization parameter with a matching name 
    Throws:
        IllegalStateException - if this ServletContext has already been initialized 
        UnsupportedOperationException - if this ServletContext was passed to the ServletContextListener#contextInitialized method of a ServletContextListener that was neither declared in web.xml or web-fragment.xml, nor annotated with WebListener
    Since:
        Servlet 3.0

So wie ich das verstehe, ein servlet-Kontext initialisiert wird, wenn eine web-Anwendung bereitgestellt wird. Wenn ich sage, servletConfig.getServletContext().setInitParameter("email", "[email protected]") innerhalb eines servlets doGet() ich bin immer IllegalStateException.

InformationsquelleAutor | 2014-03-06
Schreibe einen Kommentar