Friday, April 4, 2008

init-param Question?

1)

<init-param>

                  <param-name>mail</param-name>

                  <param-value>GaneshBR</param-value>

            </init-param>

     

            <init-param>

                  <param-name>mail</param-name>

                  <param-value>Ganesh</param-value>

            </init-param>

 

For the above entry , what will be the output for

String value=getServletConfig().getInitParameter("mail");?

 

Ans:

Ganesh

 

It will take last in order.

 

2)       if there is no init-param, then String value=getServletConfig().getInitParameter("mail”)—null, it will not throw any exception

 

3)       <init-param>

                  <param-name>mail</param-name>

                  <param-value>GaneshBR</param-value>

            </init-param>

           

            <context-param>

                  <param-name>mail</param-name>

                  <param-value>Ganesh</param-value>

            </context-param>

                 

            Which <param-name> will it return?

           

            String value=getServletConfig().getInitParameter("mail”)—Servlet init param

            String value=getServletConfig().getServletContext().getInitParameter("mail”)—Context init param

           

3)       please note that

<init-param>

                  <param-name>mail</param-name>

                  <param-value>GaneshBR</param-value>

            </init-param>

 

                        Will be inside servlet and

                         <context-param>

                  <param-name>mail</param-name>

                  <param-value>Ganesh</param-value>

            </context-param>

                        Will be outside of all servlets

            4) you can pass only string values for both of these.

No comments:

Post a Comment