SCWCD
Question 6
Let's assume you are developing a web application. One of the requirements of this application is to design a flexible framework so that services can be easily added and removed without affecting existing components.
For instance, services such as logging, authentication, debugging, compressing and encoding output, etc.. should be "pluggable" without requiring changes to the core application code. Which of the following design patterns can be used in this situation?
· A) Intercepting Filter
· B) Transfer Object
· C) Business Delegate
· D) Data Access Object
Answer
A
Specifically, the Intercepting Filter design pattern can be used when pre-processing and post-processing of a client Web request and response are required. Pluggable filters can be created to intercept all incoming and outgoing services, and process common services in a standard manner.
As the filters intercept incoming and outgoing requests, the filters can decorate the main processing logic with a variety of common services, such as security, authentication, logging, encoding, etc.
Question 7
Let's assume you are writing a JSP page using EL expressions. You have an variable declared as java.util.Map customerMap. You need to retrieve the customer info that is stored in this map.
Which of the following methods is invoked by the JSP engine upon execution of the following EL expression: ${customerMap[CustomerA]}?
· A) customerMap.get (pageContext.findAttribute ("CustomerA"));
· B) customerMap.get("CustomerA")
· C) customerMap.remove ("CustomerA");
· D) customerMap.getProperty ("CustomerA");
· E) customerMap.getCustomerA ();
Answer
A
Question 8
What will be the output of the following JSP page?
<html><body>
<% a = 100; %>
<% int a = 200; %>
<%! int a = 300; %>
a = <%= a %>, <%= this.a %>
</body></html>
A) a = 200, 100
B) a = 300, 100
C) a = 100, 200
D) a = 200, 300
E) The code will not compile as written
Answer
A
The <%! int a = 300; %> declaration will create a class-level instance variable "a", and initialize the variable to 300. The scriplet <% a = 100; %> will change the value of the class-level instance variable from 300 to 100.
The second scriplet, <% int a = 200 %>, will create a local variable "a" in the _jspService () method and set the initial value to be 200. The first expression <%= a %> refers to the local variable "a", which is 200.
The second expression <%= this.a %> uses the keyword this and refers to the class-level instance variable "a". The class-level instance variable "a" was set to 100 by the scriplet <% a = 100; %>. Hence, the correct answer is "a=200, 100"
Question 9
Which of the following files is the correct name and location of deployment descriptor of a 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
CThe deployment descriptor must be called web.xml and be placed in the directory named WEB-INF.