Lernkarten

Karten 135 Karten
Lernende 1 Lernende
Sprache English
Stufe Andere
Erstellt / Aktualisiert 12.09.2017 / 10.10.2017
Lizenzierung Keine Angabe     (Fabrizi)
Weblink
Einbinden
0 Exakte Antworten 135 Text Antworten 0 Multiple Choice Antworten
Fenster schliessen

How can an e-mail-adress be set as servlet initialization parameter 
inside the DD and retrieved from within the servlet?

DD:

<servlet>
    <init-param>
        <param-name>
myEmail</param-name>
        <param-value>
myEmail@home.de</param-value>  
    </init-param>

</servlet>

Servlet:

getServletConfig().getInitParameter("myEmail")

Fenster schliessen

What is the main difference between <init-param> and <context-param>?

Context-parameters are visible for the whole web-app,
initialization parameters only for the servlet.

Fenster schliessen

How can an e-mail-adress be set as context parameter
inside the DD and be retrieved from within a servlet?

DD:

<web-app ...>
    <context-param>
        <param-name>
myEmail</param-name>
        <param-value>
myEmail@home.de</param-value>  
    </context-param>

</web-app>

Servlet:

getServletContext().getInitParameter("myEmail")

Fenster schliessen

When and how can initialization parameters be changed?

Only at deploy time inside the Deployment Descriptor.

Fenster schliessen

Which methods do exist in the ServletContext interface
to retrieve a list of all init parameters, attributes or to delete an attribute?

getInitParameterNames(), getAttributeNames(), removeAttribute(...)

Fenster schliessen

Which of these calls is legal from inside an HttpServlet?

getServletConfig().getServletContext().getInitParameter() 
this.getServletContext().getInitParameter()

both!

(A servlet’s ServletConfig object always holds a reference
to the ServletContext for that servlet.)

Fenster schliessen

What's the use of a ServletContextListener?

Execute operations on initialization and/or termination of a web-app
and provide globally accessible context attributes.

Fenster schliessen

Which interface has to be implemented and which methods overridden
in order to establish a database connection on deployment of a web-app,
store the connection as context attribute and close it 
on undeployment or termination of the web-app?

implement ServletContextListener and override both
public void contextInitialized(ServletContextEvent event) and 
public void contextDestroyed(ServletContextEvent event)