• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query from mock exam

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There was question in amock exam on net. I am unable to understand this

Q: - Given following deployment discriptor -

<web-app version="2.4">

<servlet>
<servlet-name>InitParamsServlet</servlet-name>
<servlet-class>scwcd14.chap02.InitParamsServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>InitParamsServlet</servlet-name>
<url-pattern>/InitParamsServlet</url-pattern>

<init-param>
<param-name>name</param-name>
<param-value>javabeat</param-value>
</init-param>

</servlet-mapping>

</web-app>

What will be the output of the following Servlet?

package scwcd14.chap02;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class InitParamsServlet extends HttpServlet {

public void init(){

ServletConfig config = getServletConfig();
System.out.println(config.getInitParameter("name"));
System.out.println(config.getInitParameter("no-name"));
}
...
}
Options are:-
(A)The Servlet will output 'javabeat null' in the Server Console.
(B)The Servlet will fail to load as the init param property 'no-name' is not mentioned in the deployment descriptor.
(C)A NullPointerException will be raised as calling getServletConfig() in the init() method will return a null reference.

answer is (A). My concern is "Are we allowed to have <init-param> in <servlet-mapping>. I thoight we can place <init-param> only in <servlet> element. Isn't DD incorrect.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I did same declaration in DD, and i did not get any error.
But the output was
null
null

Kathir
 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes..servlet mapping is not allowed init-param. you can read more here:http://e-docs.bea.com/wls/docs81/webapp/components.html#148787
 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange...there is no option of "null null" and "not even problem with DD".
 
reply
    Bookmark Topic Watch Topic
  • New Topic