SCWCD-1

04/14/2008

3 Comments

 

Which of the following files is the correct name and location of deployment descriptor of web application. Assume that the web application is rooted at \doc-root. Select the one correct answer ?
A \doc-root\dd.xml
B doc-root\web.xml
C \doc-root\WEB-INF\web.xml
D \doc-root\WEB_INF\web.xml
E \doc-root\WEB-INF\classes\web.xml

Answer
C
The deployment descriptor must be called web.xml and be placed in the directory named WEB-INF.

Which element of the deployment descriptor is used to specify the class of the Servlet. ?
A <servlet-class>
B <servlet-name>
C <servlet_name>
D <servlet_class>
E <servlet>

Answer
A
The element servlet-class specifies the class of servlet.

Which of the following statements is true regarding MyServlet?
import javax.servlet.*;
;import javax.servlet.http.*;
import java.io.*;
public class MyServlet extends HttpServlet implements SingleThreadModel{
String myName;
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = res.getWriter();
myName = req.getParameter("name");
sayHello(out);
out.close();
}
public void sayHello(PrintWriter out) {
out.println("Hello " + myName);
}
}
A MyServlet is thread safe
B MyServlet is not thread safe because myName is an instance variable
C MyServlet is not thread safe because MyServlet implements SingleThreadModel.
D None of the above

Answer
A
Choice A is correct. A application is thread safe if it always behaves predictably regardless of the number of concurrent threads running in its process space. The simplest way to ensure that a servlet is thread safe is to implement the SingleThreadModel interface. By implementing this interface, the server guarantees that no more than one thread can execute the service(), doGet(), or doPost() method at a time for a particular servlet instance. This makes the servlet thread safe. Thus even if class MyServlet has instance variables, it is thread safe. Thus A is the correct choice and the other choices are incorrect.

Which of the following combinations regarding Design Patterns are correct?
A Business Delegate - Reduces the coupling between presentation-tier clients and business services.
B Data Access Object - Allows for Multiple Views using the same model
C MVC - Enables easier migration to different persistence storage implementations.
D Value Object - Reduces Network Traffic

Answer
A and D
Choices A and D are correct. In a normal scenario, presentation-tier components (e.g. a JSP) interact directly with business services. As a result, the presentation-tier components are vulnerable to changes in the implementation of the business services: when the implementation of the business services change, the code in the presentation tier must change. The goal of the Business Delegate object design pattern is to minimize the coupling between presentation-tier clients and the business service API, thus hiding the underlying implementation details of the service. Thus choice A is correct. Choice B is incorrect as it's the MVC design pattern rather than the DAO (Data Access Object), which provides Multiple Views using the same model. Choice C is incorrect as it's the DAO (Data Access Object) pattern, which enables easier migration to different persistence storage implementations. The Value Object is used to encapsulate the business data. A single method call is used to send and retrieve the Value Object. When the client requests business data from an enterprise bean, the enterprise bean can construct the Value Object, populate it with its attribute values, and pass it by value to the client. Thus choice D is also correct.

Which of these is true about deployment descriptors. Select one correct answer.
A The order of elements in deployment descriptor is important. The elements must follow a specific order.
B The elements of deployment descriptor are not case insensitive
C The servlet-mapping element, if defined, must be included within the servlet element.
D The web-app element must include the servlet element

Answer
A
The servlet specifications specifies a specific order of deployment descriptor. b is incorrect because elements are case-sensitive. The servlet-mapping element should be included within the element. So c is incorrect. All the elements within the web-app element are optional. So d is incorrect.

Which element of the deployment descriptor includes the exception-type as a sub-element ?
A <exception>
B <error-page>
C <error>
D <exception_type>
E <error_page>

Answer
B
The element error-page includes the element web-app.

Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.
A 404 /error.jsp
B mypackage.MyException 404 /error.jsp
C mypackage.MyException 404
D mypackage.MyException /error.jsp

Answer
A and D
error-page element must include either exception-type or error-code element but not both. It must also include the location element.

Which element of the deployment descriptor of a web application includes the welcome-file-list element as a sub element.
A <welcome>
B <welcome-files>
C <list>
D <web-app>
E <context>

Answer
D
The contains the element.

Which of these is a correct example of specifying a listener element resented by MyClass class. Assume myServlet element is defined correctly. Select one correct answer.
A MyClass
B MyClass
C aListener MyClass
D <> myServlet MyClass

Answer
B
The element listener-class must be included within the listener element.

Which of the following is legal JSP syntax to print the value of i. Select the one correct answer
A <%int i = 1;%><%= i; %>
B <%int i = 1;i; %>
C <%int i = 1%><%= i %>
D <%int i = 1;%><%= i %>
E <%int i = 1%><%= i; %>

Answer
D
When using scriptlets (that is code included within ), the included code must have legal Java syntax. So the first statement must end with a semi-colon. The second statement on the other hand is a JSP expression. So it must not end with a semi colon.

 


Comments

asf
05/20/2008 17:20

Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.
A 404 /error.jsp
B mypackage.MyException 404 /error.jsp
C mypackage.MyException 404
D mypackage.MyException /error.jsp

should be:

A <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
B <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
C <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> </error-page>
D <error-page> <exception-type>mypackage.MyException</exception-type> <location>/error.jsp</location> </error-page>

Reply
asf
05/20/2008 17:22

oops..

<![CDATA[
Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.
A 404 /error.jsp
B mypackage.MyException 404 /error.jsp
C mypackage.MyException 404
D mypackage.MyException /error.jsp

should be

A <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
B <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
C <error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> </error-page>
D <error-page> <exception-type>mypackage.MyException</exception-type> <location>/error.jsp</location> </error-page>
]]>

Reply
asf
05/20/2008 17:23

for some reason it eats all tags from my post..

Reply



Leave a Reply

    SCWCD Sets


    Archives

    May 2008
    April 2008