A servlet wishes to indicate that it is unable to initialize at the present time, but that the initialization might succeed at some future time. Which is true?
Answer : E
A web application for business expense reporting allows uploading expense receipts.
Multiple receipts can be uploaded single step using one HTTP request. The servlet that processes the request has been marked with the @MultipartConfig annotation.
Which method should the servlet use to access the uploaded files?
Answer : A
Explanation: The request.getParts() method returns collections of all Part objects. If you have more than one input of type file, multiple Part objects are returned. Since Part objects are named, the getPart(String name) method can be used to access a particular Part.
Alternatively, the getParts() method, which returns an Iterable<Part>, can be used to get an
Iterator over all the Part objects.
When using the @WebListener annotation, the class on which the annotation is applied to must also implement at least one o the following interfaces (Choose two):
Answer : C,D
Explanation: @WebListener -
The main task of the listener is to listen the particular events and process your own task on that event. For example, if you want to initialize a database connection before your application starts, ServletContextListener will be implemented to do that. Another good example is -when you want to do some task on the creation and destruction of a session.
For this purpose you need to implement HttpSessionListener.
View the Exhibit.
Answer : A
Assume a JavaBean com.example.GradedTestBean exists and has two attributes. The attribute name of type java.lang.string and the attribute score is of type jave.lang.Integer.
An array of com.example.GradedTestBean objects is exposed to the page in a request- scoped attribute called results. Additionally, an empty java.util.HashMap called resultMap is placed in the page scope.
A JSP page needs to add the first entry in results to resultMap, storing the name attribute of the bean as the key and the score attribute of the bean as the value.
Which code snippet of JSTL code satisfies this requirement?
Answer : E
A servlet class is injected with a JDBC data source. After injection has occurred, the servlet needs to create a cache out of some of the data in the database, so as to improve responsiveness.
Which two methods can host the cache creation code? (Choose two)
Answer : A,D
Explanation: A: Because the Servlet init() method is invoked when the servlet instance is loaded, it is the perfect location to carry out expensive operations that need only be performed during initialization. By definition, the init() method is thread-safe. The results of operations in the HttpServlet.init() method can be cached safely in servlet instance variables, which become read-only in the servlet service method.
D: Example:
@PostConstruct
private void init() {
cached = (Cached) ctx.lookup(EJB_PATH + Cached.class.getSimpleName());
During initialization, a servlet finds that the database connection it requires is unavailable.
As the system designer, you know that the database start up completes several minutes after the web- container initializes the servlet. How should this be handled?
Answer : D
Reference: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets6.html
Given this fragment in a servlet:
23. if(reg.isUserInRole(Admin)) {
24. // do stuff
25. }
And the following fragment from the related Java EE deployment descriptor:
812. <security-role-ref>
813. <role-name>Admin</role-name>
814. <role-link>Administrator</role-link>
815. </security-role-ref>
900. <security-role>
901. <role-name>Admin</role-name>
902. <role-name>Administrator</role-name>
903. </security-role>
What is the result?
Answer : D
Given a war file with the following structure
| - WEB-INF/classes/Myservlet.class
| - WEB-INF/lib/wf.jaf
Where wf.jar contains a valid web-fragment.xml and the following two classes:
MyFilter1.class and MyFiler2.class.
The web-fragment.xml is as follows:
Answer : C
Explanation:
Note:
* <filter-mapping>
This tag specifies a filter name, and either a URL mapping or servlet name, for a filter that has been defined with the <filter> tag.
Multiple <filter-mapping> tags can be specified for a single <filter>, providing different URL patterns. See the <url-pattern> tag for examples.
The <filter-mapping> has two required elements:
<filter-name> - the filter name, as specified in the <filter-name> element of the <filter> tag
Either a <url-pattern> or a <servlet-name>.
If a servlet name is specified, the filter will be called whenever the specific servlet is called.
Which is a benefit of precompiling a JSP page?
Answer : C
The jquery_1_3_2.jar file contains the JQuery Ajax framework in its META-INF/ resources directory. Where should the jar file be placed inside the web application to ensure the resources it contains are accessible by clients?
Answer : C
Reference:
http://www.ibm.com/developerworks/websphere/library/techarticles/0112_deboer/deboer.ht ml (topic: web modules, third paragraph)
Servlet A forwarded a request to servlet B using the forward method of RequestDispatcher.
What attribute in Bs request object contains the URI of the original request received by servlet A?
Answer : B
A web application allows the HTML title banner to be set using a context initialization parameter called titlestr.
Which two properly set the title in the scenario? (Choose two)
Answer : B,E
Given the fragment from Java EE deployment descriptor:
341. <error-page>
342. <exception-type>java.lang.Throwable</exception-type>
343. <location>/mainError.jsp</location>
344. </error-page>
345. <error-page>
346. <exception-type>java.lang.ClassCastException</exception-type>
347. <location>/castError.jsp</location>
348. </error-page>
If the web application associated with the fragment above throws a ClassCastException.
Which statement is true?
Answer : C
Given that a web application consists of two HttpServlet classes, ServletA and ServletB, and the ServerletA.service method:
20. String key = com.example.data;
21. session.setAttribute(key, Hello);
22. object value = session.getAttribute(key);
23.
Assume session is an HttpSession, and is not referenced anywhere else in ServletA.
Which two changes, taken together, ensure that value is equal to Hello on line 23?
(Choose two)
Answer : C,E