Total Pageviews

Friday, 22 January 2016

STRUCTURE AND DEPLOYMENT Interview Questions & Answers

Q.1 Which element is used to specify useful information about an initialization parameter of a servlet in the deployment descriptor? (Select one).
a. param-description
b. description
c. info
d. param-info
e. init-param-info
Answer: b
Explanation
Remember that the description element is used for all the elements that can take a description (useful information about that element). This includes servlet, init-param, and context-param, among others. For a complete list of the elements that can take a description, please read the DTD for web.xml.
Q.2 Which of the following deployment descriptor snippets correctly associates a servlet implemented by a class named com.abc.SalesServlet with the name SalesServlet? (Select one)
a. <servlet>
       <servlet-name>com.abc.SalesServlet</servlet-name>
       <servlet-class>SalesServlet</servlet-class>
    </servlet>
b. <servlet>
       <servlet-name>SalesServlet</servlet-name>
       <servlet-package>com.abc.SalesServlet</servlet-package>
     </servlet>
c. <servlet>
      <servlet-name>SalesServlet</servlet-name>
      <servlet-class>com.abc.SalesServlet</servlet-class>
    </servlet>
d. <servlet name=”SalesServlet” class=”com.abc.SalesServlet”>
       <servlet>
         <servlet-class name=”SalesServlet”>com.abc.SalesServlet</servlet-class>
     </servlet>
e. <servlet>
       <servlet-name class=”com.abc.SalesServlet”>SalesServlet</servlet-name>
     </servlet>
Answer: c
Explanation
A servlet is configured using the servlet element. Here is the definition of the servlet element:
<!ELEMENT servlet ( icon?, servlet-name, display-name?, description?,
(servlet-class|jsp-file), init-param*, load-on-startup?, run-as?, security-role-ref* ) >
Q.3 A web application is located in a directory named sales. Where should its deployment descriptor be located? (Select one)
a. sales
b. sales/deployment
c. sales/WEB
d. sales/WEB-INF
e. WEB-INF/sales
f. WEB-INF
g. WEB/sales
Answer: d
Explanation
The deployment descriptor is always located in the WEB-INF directory of the web application.
Q.4 What file is the deployment descriptor of a web application named BankApp stored in? (Select one)
a. BankApp.xml
b. bankapp.xml
c. server.xml
d. deployment.xml
e. WebApp.xml
f. web.xml
Answer: f
Explanation
The deployment descriptor of a web application is always kept in a file named web.xml, no matter what the name of the web application is.
Q.5 Your servlet class depends on a utility class named com.abc.TaxUtil. Where would you keep the TaxUtil.class file? (Select one)
a. WEB-INF
b. WEB-INF/classes
c. WEB-INF/lib
d. WEB-INF/jars
e. WEB-INF/classes/com/abc
Answer: e
Explanation
All the classes that are not packaged in a JAR file must be kept in the WEB-INF/classes directory with its complete directory structure, as per the package of the class. The servlet container automatically adds this directory to the classpath of the web application.
Q.6 Your web application, named simpletax, depends on a third-party JAR file named taxpackage.jar. Where would you keep this file? (Select one)
a. simpletax
b. simpletax/WEB-INF
c. simpletax/WEB-INF/classes
d. simpletax/WEB-INF/lib
e. simpletax/WEB-INF/jars
f. simpletax/WEB-INF/thirdparty
Answer: d
Explanation
All the classes that are packaged in a JAR file must be kept in the WEB-INF/lib directory. The servlet container automatically adds all the classes in all the JAR files kept in this directory to the classpath of the web application.
Q.7 Which of the following deployment descriptor elements is used to specify the initialization parameters for a servlet named TestServlet? (Select one)
a. No element is needed because initialization parameters are specified as attributes of the <servlet> element.
b. <servlet-param>
c. <param>
d. <initialization-param> 
e.<init-parameter>
f. <init-param>
Answer: f
Explanation
Each initialization must be specified using a separate <init-param> element:
<!ELEMENT init-param (param-name, param-value, description?)>
The following is an example of a servlet definition that specifies two initialization parameters:
<servlet>
  <servlet-name>TestServlet</servlet-name>
  <servlet-class>com.abc.TestServlet</servlet-class>
  <init-param>
    <param-name>MAX</param-name>
    <param-value>100</param-value>
    <description>maximum limit</description>
  </init-param>
  <init-param>
    <param-name>MIN</param-name>
    <param-value>10</param-value>
  </init-param>
</servlet>
Q.8 Assume that the following servlet mapping is defined in the deployment descriptor of a web application:
<servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>*.asp</url-pattern>
</servlet-mapping>
Which of the following requests will not be serviced by TestServlet? (Select one)
a. /hello.asp
b. /gui/hello.asp
c. /gui/hello.asp/bye.asp
d. /gui/*.asp
e. /gui/sales/hello.asp
f. /gui/asp
Answer: f
Explanation
Here, any request that ends with .asp will be directed to TestServlet. Thus, only answer f will not be serviced by TestServlet. We suggest that you identify the context path, servlet path, and path info for all the above options according to the rules given in section 5.2.4.

No comments: