**1. **Considering Servlets 3.0 and listeners invocation order, choose statements that are true: a. b. c. d.

the order the order names, the order the order listeners. is always unspecified, is specified by alphabetically sorted listener implementation class is unspecified when using annotations to define listeners, can be defined only when using Deployment Descriptor to define

**2. **Considering the following HTML form code snippet and the servlet code, what will be the result of servlet invocation after the form has been submitted? <!-- form.html --> <form action="myServlet?var=q1&var=q2" method="POST"> <input name="var" type="hidden" value="q3" /> <input type="submit" /> </form> package com.nullhaus; import javax.servlet.annotation.*; import javax.servlet.http.*; import java.io.*; @WebServlet("/myServlet") public class NullServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) { String param = req.getParameter("var"); resp.getWriter().println("[" + param + "]"); } } [q1, q2], [q3], [q2], [q1], [q1, q2, q3], [q3, q2, q1], [null], the above code doesn’t compile.

a. b. c. d. e. f. g. h.

**3. **Considering the following HTML form code snippet and the servlet code, what will be the result of servlet invocation after the

form has been submitted? <!-- form.html --> <form action="myServlet?var=q1&var=q2" method="POST"> <input name="var" type="hidden" value="q3" /> <input type="submit" /> </form> package com.nullhaus; import import import import javax.servlet.annotation.*; javax.servlet.http.*; java.io.*; java.util.*;

@WebServlet("/myServlet") public class NullServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) { String[] param = req.getParameterValues("var"); resp.getWriter().println(Arrays.toString(param)); } a. b. c. d. e. f. g. h. } [q1, q2], [q3], [q2], [q1], [q1, q2, q3], [q3, q2, q1], [null], the above code doesn’t compile.

**4. **Assume that the Deployment Descriptor consists of the

following mapping rules: /security/* => MyServlet What will be the values of HttpServletRequest#getServletPath() and HttpServletRequest#getPathInfo() for the following request: /myApp/security/p.html?var=q1 a . b . c . d . e . f. ServletPath = /security/p.html PathInfo = /p.html

ServletPath = /security/p.html?var=q1

PathInfo = /p.html?var=q1

ServletPath = /security/p.html?var=q1

PathInfo = null

ServletPath = /security

PathInfo = /p.html

ServletPath = /security

PathInfo = /p.html?var=q

This mapping is invalid because the “security” is a reserved mapping for container authentication and authorization purposes.

**5. **Considering Servlets 3.0, you can programmatically: a. b. c. d. e. f. g. add servlets, add filters, add listeners, instantiate servlets class, instantiate filters class, access already registered servlets and filters, modify url patterns the servlets / filters maps to.

6. Considering Servlets 3.0, you can programmatically add servlets / filters: a. b. c. d. e. f. only from ServletContextListener, only from ServletContainerInitializer, only from class which is configured with DD element or loadOnStartup attribute of the @WebServlet annotation with value > 0, only a and b are correct, only a and c are correct, only b and c are correct,

g.

a, b and c are all correct.

**7. **Considering Servlets 3.0, you can access registered servlets: a. b. c. d. e. which were registered programatically, which were registered using annotations, which were registered using deployment descriptor and web fragments, you cannot access already registered servlets, none of the above is correct. **8. **Considering Servlets 3.0, which listeners can be added programatically: a. b. c. d. e. f. g. h. ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener, HttpSessionActivationListener, HttpSessionAttributeListener, HttpSessionBindingListener, you cannot add listeners programatically.

**9. ** Consider the test.jsp page code shown below: <%@page contentType="plain/text" %> Hello ${world}! What will be the result of the request made to the following servlet: package com.nullhaus; import javax.servlet.annotation.*; import javax.servlet.http.*; import java.io.*; @WebServlet("/foo/*") public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { ServletContext ctx = getServletContext(); InputStream is = ctx.getResourceAsStream("/test.jsp"); byte[] b = new byte[is.available()]; is.read(b); resp.getWriter().print(new String(b)); } }

a. b. c. d. e.

<%@page contentType="plain/text" %>Hello ${world}! <%@page contentType="plain/text" %>Hello ! <%@page contentType="plain/text" %>Hello null! (Java servlet code which is a result of the translation of test.jsp file), The above code doesn’t compile.

10. Consider the following Deployment Descriptor code snippet: ... <filter> <filter-name>MyFilter 1</filter-name> <filter-class>com.nullhaus.MyFilter</filter-class> </filter> <filter> <filter-name>MyFilter 2</filter-name> <filter-class>com.nullhaus.MyFilter</filter-class> </filter> ... Knowing that the com.nullhaus.MyFilter is a valid Filter class, the above snippet is the only filter-related DD part and that there aren’t any annotations related to the filter configuration, how many filter instances will be created by the Servlet container? a. b. c. d. 1 2 Deployment Descriptor is invalid and the runtime exception will be thrown

**11. **Consider the following Deployment Descriptor code snippet: ... <filter> <filter-name>MyFilter 1</filter-name> <filter-class>com.nullhaus.MyFilter</filter-class> </filter> <filter> <filter-name>MyFilter 1</filter-name> <filter-class>com.nullhaus.MyFilter2</filter-class> </filter> ... Knowing that the com.nullhaus.MyFilter and com.nullhaus.MyFilter2 are valid Filter classes, the above snippet is the only filter-related DD part and that there aren’t any annotations related to the filter configuration, how many filter instances will be created by the Servlet container? a. b. 1

nullhaus. Knowing that the com.MyFilter</filter-class> </filter> ...servlet.*. and the following Filter code: package com.nullhaus. d. import javax. 1 2 Deployment Descriptor is invalid and the runtime exception will be thrown **13.servlet. how many filter instances will be created by the Servlet container? a. <filter> <filter-name>NullFilter 1</filter-name> <filter-class>com.nullhaus. **Consider the following Deployment Descriptor code snippet: . import javax. how many filter instances will be created by the Servlet container? a.annotation....NullFilter</filter-class> </filter> ..MyFilter</filter-class> </filter> <filter> <filter-name>MyFilter 1</filter-name> <filter-class>com. d. @WebFilter("/*") public class NullFilter implements Filter { // necessary methods goes here } Knowing that above DD snippet is the only filter-related part. 2 Deployment Descriptor is invalid and the runtime exception will be thrown **12.*.c.nullhaus. **Consider the following Deployment Descriptor code snippet: ... the above snippet is the only filter-related DD part and that there aren’t any annotations related to the filter configuration.MyFilter is a valid Filter class.nullhaus. . c. <filter> <filter-name>MyFilter 1</filter-name> <filter-class>com. b.

*. this DD is valid. 1 2 Deployment Descriptor is invalid and the runtime exception will be thrown **15. how many filter instances will be created by the Servlet container? a.annotation. **Consider the below filter-mapping definition in the Deployment Descriptor: <filter> <filter-name>MyFilter 1</filter-name> <filter-class>com.nullhaus.servlet. assuming that MyFilter 1 is valid and runs without a grasp: a..servlet. c. filterName="NullFilter 1") public class NullFilter implements Filter { // necessary methods goes here } Knowing that above DD snippet is the only filter-related part. c.. import javax.. **Consider the following Deployment Descriptor code snippet: .MyFilter</filter-class> </filter> <filter-mapping> <filter-name>MyFilter 1</filter-name> <url-pattern>/bar/*</url-pattern> <servlet-name>YourServlet</servlet-name> <url-pattern>/baz/*</utl-pattern> </filter-mapping> What is true about the above DD snippet. and the following Filter code: package com.b.nullhaus.nullhaus.NullFilter</filter-class> </filter> . d. b. d. 1 2 Deployment Descriptor is invalid and the runtime exception will be thrown **14. @WebFilter(urlPatterns = {"/*"}..*. <filter> <filter-name>NullFilter 1</filter-name> <filter-class>com. . import javax.

REQUEST. ASYNC. The “NullHaus Filter” will be accessed only if the RequestDispatcher#include(-) method is invoked from a RequestDispatcher obtained by name. The above filter annotation is functionally equal to the below DD part: <filter> <filter-name>NullHaus Filter</filter-name> .nullhaus. this DD is valid but will throw a runtime exception when “Myfilter 1″ url pattern will be matched.*. JSP. dispatcherTypes = {DispatcherType. The “NullHaus Filter” will be accessed only if the RequestDispatcher#include(-) method is invoked from a RequestDispatcher obtained by path. which statements are true: a. d. f. ERROR. c. because there can’t be a element in .servlet. 17.b.annotation. because there can’t be more than one element in . INCLUDE. e. c.*. this DD is invalid. The “NullHaus Filter” will be accessed if the RequestDispatcher#include(-) method is invoked from a RequestDispatcher obtained either by name or path. this DD is invalid. import javax. **16. The “*” is not a valid servletNames attribute value and a runtime exception will be thrown.INCLUDE}) public class NullFilter implements Filter { // necessary methods goes here } Assuming that there aren’t any filter-related parts in the DD. FORWARD. b. because there can’t be a element together with element in . e. d. Consider the following Filter code: package com. @WebFilter(servletNames = {"*"}. this DD is invalid. c. e. import javax. **Which of the following values are valid RequestDispatcher types: a.servlet. d. b. filterName="NullHaus Filter".

b. but the ordering rules can be specified in the Deployment Descriptor. e. and it depends on the web-fragment. This filter-mapping is valid and the “NullHaus Filter” will be accessed each time a request is dispatched from a RequestDispatcher obtained either by name or path.xml’s element value. The order of web fragments scanning/discovering is always specified. This filter-mapping is invalid. and it depends on the alphabetical order of JARs in which the web-fragments are located in. The order of web fragments scanning/discovering is always specified. and it depends on the container specific implementation. which statements are true: a. **Consider the following element in the Deployment Descriptor: <filter-mapping> <filter-name>NullHaus Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> This filter-mapping is valid and the “NullHaus Filter” will be accessed each time a request is made to the web application. a.NullFilter</filter-class> </filter> <filter-mapping> <filter-name>NullHaus Filter</filter-name> <servlet-name>*</servlet-name> <dispatcher>INCLUDE</dispatcher> </filter-mapping> **18. **20.nullhaus. The order of web fragments scanning/discovering is unspecified by default. and it depends on the web-fragment.<filter-class>com. b. **Considering the idea of web fragments. **19. which statements are true: . d. This filter-mapping is valid and the “NullHaus Filter” will be accessed only if the request is made to the web application root context (/). d. The order of web fragments scanning/discovering is always unspecified.xml’s element value. The order of web fragments scanning/discovering is always specified. c. **Considering the ordering of web fragments. c.

e. c.xml. If a web fragment is packaged as a JAR file.xml. . Fragment 1.xml. must be named “web_fragment. **22. Fragment 2. must be named “web-fragment.xml“. it must be located directly under WEB-INF/ directory of the application.xml <web-fragment> <name>Fragment 2</name> </web-fragment> web. Fragment 2. e.xml <web-fragment> <name>Fragment 1</name> <absolute-ordering> <name>Fragment 2</name> </absolute-ordering> </web-fragment> web-fragment. If a web fragment packaged as a JAR file needs to be discovered by the container. web. Fragment 2. **What will be the order in which the container will scan and a. web. If a web fragment packaged as a JAR file needs to be discovered by the container. its web fragment XML file needs to be located directly under META-INF/ directory of the JAR file. it must be located directly under WEB-INF/lib directory of the application.a.xml. web fragment’s filename.xml. to be discovered by the container. Fragment 1. Fragment 2. web. **21. d.xml. b. its web fragment XML file needs to be located at the top directory of the JAR file. g. If a web fragment is packaged as a JAR file. d. **What will be the order in which the container will scan and combine web fragments to form the effective Deployment Descriptor (attributes for and intentionally omitted. b. At least one of the above Deployment Descriptors is invalid. web. Fragment 1. web. f. If a web fragment packaged as a JAR file needs to be discovered by the container. web fragment’s filename. h. Fragment 1. assume the default values): web. web. Fragment 1. g.xml. Fragment 2. f. it must be located somewhere in the application’s classpath.xml <web-app> </web-app> web-fragment. to be discovered by the container.xml“. c.

xml <web-fragment> <name>Fragment 2</name> </web-fragment> web. web. Fragment 1. c.combine web fragments to form the effective Deployment Descriptor (attributes for and intentionally omitted.xml.xml <web-app metadata-complete="false"> <absolute-ordering> <name>Fragment 1</name> <name>Fragment 2</name> </absolute-ordering> </web-app> web-fragment.xml. g. Fragment 1. **23. web. web. assume the default values): web. b. web.xml <web-fragment> <name>Fragment 1</name> </web-fragment> web-fragment. **What will be the order in which the container will scan and combine web fragments to form the effective Deployment Descriptor (attributes for and intentionally omitted. Fragment 2.xml. d.xml. assume the default values): web. web.xml.xml <web-fragment> <name>Fragment 1</name> <ordering> <after>Fragment 2</after> </ordering> . e.xml. h.xml. Fragment 2. Fragment 1. Fragment 2. a. f. Fragment 2. Fragment 1. Fragment 1.xml <web-app> <absolute-ordering> <name>Fragment 2</name> </absolute-ordering> </web-app> web-fragment. web. Fragment 2. At least one of the above Deployment Descriptors is invalid.

b. Fragment 2. web. At least one of the above Deployment Descriptors is invalid.xml. Fragment 1. Fragment 1. **24. Fragment 2. web. Fragment 2. d. a. c. assume the default values): web. web. web. Fragment 1. web. web.xml. Fragment 2.</web-fragment> web-fragment. web. **25. Fragment 1. b.xml.xml.xml <web-app metadata-complete="true"> <absolute-ordering> <name>Fragment 1</name> <name>Fragment 2</name> </absolute-ordering> </web-app> web-fragment. Fragment 1. Fragment 1.xml. At least one of the above Deployment Descriptors is invalid and will thrown a runtime exception. Fragment 1. **What will be the order in which the container will scan and .xml.xml. web. Fragment 2. e.xml <web-fragment> <name>Fragment 2</name> </web-fragment> web. d.xml. e.xml.xml <web-fragment> <name>Fragment 1</name> <ordering> <after>Fragment 2</after> </ordering> </web-fragment> web-fragment. Fragment 2. c.xml <web-fragment> <name>Fragment 2</name> </web-fragment> web. **What will be the order in which the container will scan and combine web fragments to form the effective Deployment Descriptor (attributes for and intentionally omitted. f. f. Fragment 2.xml. Fragment 1. Fragment 2. a.

xml <web-fragment metadata-complete="true"> <name>Fragment 1</name> <ordering> <after>Fragment 2</after> </ordering> </web-fragment> web-fragment. d. b. **Choose statements that are true about the metadatacomplete attribute — for element in web. choose the statements which are true: . web. but element within the .xml <web-fragment> <name>Fragment 2</name> </web-fragment> web. c. Fragment 2. f. @WebServlet.xml <web-app> <absolute-ordering> <name>Fragment 1</name> <name>Fragment 2</name> </absolute-ordering> </web-app> web-fragment. This attribute is purely informational and does not affect how container processes the final Deployment Descriptor. Fragment 1.xml. Fragment 1.xml to create final Deployment Descriptor. This attribute can define if the container should scan and process the new Servlets 3. d.combine web fragments to form the effective Deployment Descriptor (attributes for and intentionally omitted.xml: a. web. b. At least one of the above Deployment Descriptors is invalid and will thrown a runtime exception. e. e. Fragment 2. assume the default values): web. Fragment 2. There is no attribute metadata-complete.0 annotations like @WebFilter. web. **26. etc. web.xml. Fragment 1. c.. Fragment 2. a. Fragment 1. **Considering the following Servlet code.xml.xml. This attribute can define if the container should scan for webfragments.xml. **27. This attribute is of a boolean type which takes true/false values only.

d. This is an invalid usage of @WebServlet annotations because of the wrongly formed url-pattern value.servlet.http. because NullHausServlet need to implement one of doGet(-). b.package com. methods.*. This code doesn’t compile. This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” url-pattern value. c. because NullHausServlet need to implement one of doGet(-).*. because the value of @WebServlet annotation attribute (“nullHausServlet”) must be defined using @WebServlet(value = “nullHausServlet”) construct. but @Servlet.servlet.*. **Considering the following Servlet code.*.servlet. This is an invalid usage of @WebServlet annotations because the “value” attribute cannot be used explicitly in the annotation. import javax.nullhaus. @WebServlet("nullHausServlet") public class NullServlet extends HttpServlet { } This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” name. import javax. b. This code doesn’t compile. e. e.annotation. a.servlet. This code doesn’t compile. This code doesn’t compile.annotation. f. This is an invalid usage of @WebServlet annotations because of the wrongly formed url-pattern value.nullhaus. import javax. etc. This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” url-pattern value. because there is no @WebServlet annotation. d. This code doesn’t compile. because there is no @WebServlet annotation. etc.http. f. a. methods. doPost(-). choose the statements which are true: package com. c. import javax. @WebServlet(value = "nullHausServlet") public class NullServlet extends HttpServlet { } This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” name. . but @Servlet. **28. doPost(-).

annotation. import javax.servlet. **Considering the following Servlet code.servlet. choose the statements which are true: package com. import javax. because the urlPatterns and value attributes cannot be defined together. a. because there is a “urlPattern” attribute – not “urlPatterns“. c. This is an invalid usage of @WebServlet annotation. The name of this servlet is “com. This is a valid usage of @WebServlet annotation.*. This is an invalid usage of @WebServlet annotation. because of the wrongly formed url-pattern value. This code doesn’t compile.annotation.http. value="/numeroDuo") public class NullServlet extends HttpServlet { } This is a valid usage of @WebServlet annotation which runs fine. This is an invalid usage of @WebServlet annotation.*. This is an invalid usage of @WebServlet annotation. because there is a “urlPattern” attribute – not “urlPatterns“. g. e.nullhaus. d. **30.nullhaus. import javax. **Considering the following Servlet code. f. This is an invalid usage of @WebServlet annotation. because the “urlPatterns” attribute should be an array of Strings – not a single String value. c.servlet.NullHausServlet“.*. b. b. choose the statements which are true: . import javax. This code doesn’t compile. e. because of the wrongly formed url-pattern value.*. a. @WebServlet(urlPatterns="/nullHausServlet") class NullHausServlet extends HttpServlet { } This is a valid usage of @WebServlet annotation which runs fine.**29.http. **31. @WebServlet(urlPatterns = {"/nullServlet"}. d. choose the statements which are true: package com.servlet. **||\ **||Considering the following Servlet code.nullhaus. but the servlet can’t be accessed. This is an invalid usage of @WebServlet annotation.

annotation.servlet. d. choose the statements which are true: . There will be a runtime exception thrown and NullHaus1 servlet will not be operational.package com. The NullHausServlet will be accessible from /foo/* and /baz/* urls.*. choose the statements which are true: package com.servlet. **32. The NullHausServlet will be accessible only from /foo/* url. h. There will be exactly two instances of the NullHausServlet. import javax.http. This code compiles. There will be at least two instances of the NullHausServlet. name="NullHaus1") public class NullHausServlet extends HttpServlet { } <servlet> <servlet-class>com.servlet. import javax. **33. @WebServlet(name="NullServlet") public class NullServlet extends HttpServlet { } This is a valid usage of @WebServlet annotation. import javax.*. g. c.nullhaus.nullhaus. The NullHausServlet will be accessible only from /baz/* url. import javax. d.servlet. c.*. This is an invalid usage of @WebServlet annotation.*. b. @WebServlet(urlPatterns={"/foo/*"}. **Considering the following Servlet code and the Deployment Descriptor snippet. a.annotation. b. e. **||\ **||Considering the following Servlet code and the Deployment Descriptor snippet. f. This code doesn’t compile. There will be at least one instances of the NullHausServlet.NullHausServlet</servlet-class> <servlet-name>NullHaus1</servlet-name> </servlet> <servlet-mapping> <servlet-name>NullHaus1</servlet-name> <url-pattern>/baz/*</url-pattern> </servlet-mapping> There will be exactly one instance of the NullHausServlet.nullhaus.http. a.

a.*. . c. @WebServlet(urlPatterns={"/foo/*"}. java. javax.annotation.nullhaus. javax.servlet.servlet. d.*.http. There will be at least two instances of the NullHausServlet.*. import javax.package com. b. @WebServlet(value = "/foo/*". name="NullHaus1") public class NullHausServlet extends HttpServlet { } <servlet> <servlet-class>com. There will be at most two instances of the NullHausServlet.annotation.nullhaus.servlet. import javax.NullHausServlet</servlet-class> <servlet-name>NullHaus2</servlet-name> </servlet> <servlet-mapping> <servlet-name>NullHaus2</servlet-name> <url-pattern>/baz/*</url-pattern> </servlet-mapping> There will be exactly one instance of the NullHausServlet.*.nullhaus. **34.http. There will be a runtime exception thrown and NullHaus1 and NullHaus2 will not be operational.servlet. **Consider the following Servlet code and the ServletContainerInitializer code.*. e.nullhaus.servlet. Assume that the MyInit class is properly registered in the container as a ServletContainerInitializer.io. import import import import javax. name="NullHaus1") public class MyJar1Servlet extends HttpServlet { } package com. Choose the statements which are true: package com.*. There will be exactly two instances of the NullHausServlet.

ServletContext ctx) throws ServletException { try { Class klass = Class.servlet. Class<MyJar1Servlet> clazz = (Class<MyJar1Servlet>)klass.*.*. There will be at least one instance of the MyJar1Servlet named NullHaus2. javax.*.nullhaus. b.servlet. } catch (ClassNotFoundException e) { // .addMapping("/baz/*"). e. } } } There will be at least one instance of the MyJar1Servlet named NullHaus1.*.*.Dynamic d = ctx. d. import java.forName("com.*.*. **35. s). ServletRegistration.createServlet(clazz)..import javax. a.addServlet("NullHaus2".servlet.io. java.http.nullhaus. name="NullHaus1") public class MyJar1Servlet extends HttpServlet { } package com. There will be exactly two instances of the MyJar1Servlet named NullHaus1 and NullHaus2 respectively.servlet. @WebServlet(value = "/foo/*". public class MyInit implements ServletContainerInitializer { public void onStartup(Set<Class<?>> c.annotation..MyJar1Servlet"). . import import import import javax. Choose the statements which are true: package com. Assume that the MyInit class is properly registered in the container as a ServletContainerInitializer. Servlet s = ctx.*. c.servlet. import java. import javax. javax. A runtime exception will be thrown. d. **Consider the following Servlet code and the ServletContainerInitializer code.util.util.nullhaus. This code doesn’t compile.

Servlet s = ctx.http.servlet.Servlet interface. This code doesn’t compile.forName("com.http. } } } There will be at least one instance of the MyJar1Servlet named NullHaus1. **Which statements are true about classes annotated with @WebServlet? a. The number of MyJar1Servlet instances is unspecified. none of the above is correct. Class<MyJar1Servlet> clazz = (Class<MyJar1Servlet>)klass.*.HttpServlet class. b.. **37.addMapping("/baz/*").*. import java. they must implement the javax. name="NullHaus1". b.MyJar1Servlet"). } catch (ClassNotFoundException e) { // .*.addServlet("NullHaus1".annotation.nullhaus. d. initParams=@WebInitParam(name="var1". they must extend the javax.servlet. import javax. ServletRegistration.createServlet(clazz).servlet. **36. @WebServlet(urlPatterns={"/foo/*"}.io. s).servlet. value="Howdy!")) public class NullHausServlet extends HttpServlet { public void doGet(HttpServletRequest req. ServletContext ctx) throws ServletException { try { Class klass = Class.nullhaus. a. c.GenericServlet class. **Consider the following servlet code: package com.servlet.public class MyInit implements ServletContainerInitializer { public void onStartup(Set<Class<?>> c.Dynamic d = ctx. they must extend the javax. c.. import javax. d. HttpServletResponse resp) throws IOException { .

getWriter(). resp. This code doesn’t compile.servlet. e. } } Choose what will be the result of the code execution: a. null. Values: Howdy!. import javax. c.io. Runtime exception will be thrown. null. HttpServletResponse resp) throws IOException { String param1 = getInitParameter("var1"). e. This code doesn’t compile. } } Choose what will be the result of the code execution: a. Values: null.servlet.print("Values: " + param1 + ". **38.print("Values: " + param1 + ". value="Howdy!") @WebServlet(urlPatterns={"/foo/*"}. Howdy!. import java. Values: Howdy!. Howdy!. **Consider the following servlet code: package com. f. b. name="NullHaus1") public class NullHausServlet extends HttpServlet { public void doGet(HttpServletRequest req. null. Values: Howdy!.getInitParameter("var1").*. @WebInitParam(name="var1". import javax.String param1 = getInitParameter("var1"). Values: null.getWriter(). Values: null. .annotation. Values: null. b. String param2 = getServletContext(). c. Values: Howdy!.getInitParameter("var1"). " + param2). d.*. String param2 = getServletContext(). f.http. Runtime exception will be thrown.*. resp. Howdy!. " + param2). d. null. Howdy!.nullhaus.

value="Rancher!") @WebServlet(urlPatterns={"/foo/*"}. **Considering the web fragments ordering rules. Rancher!. 41. b.servlet. The element can be placed within the web-fragment.*. f. e. null. b. d. Values: Howdy!. Runtime exception will be thrown.print("Values: " + param1 + ". The only possible elements of are . e. String param2 = getInitParameter("var2"). .getWriter(). value="Howdy!") @WebInitParam(name="var2". } } Choose what will be the result of the code execution: a. d. the order of web fragments scanning is unspecified. f. If there are no nor elements defined in web. **40. HttpServletResponse resp) throws IOException { String param1 = getInitParameter("var1"). b.servlet. name="NullHaus1") public class NullHausServlet extends HttpServlet { public void doGet(HttpServletRequest req. g.*.io. Which statements are true: a. c. The element can be placed within the web. Values: null.*. null.**39. Rancher!.xml file. which statements are true: a. import javax. The element can be placed within the web. and .xml file. @WebInitParam(name="var1".xml file. resp. The element (subelement of ) set to “false” forces the container to make the servlet unreachable for request to the defined url-pattern.xml. Values: null. import javax. The element can be placed within the web-fragment. " + param2). c. import java.nullhaus. Values: Howdy!.xml file. **Consider the following servlet code: package com. The only possible elements of the element are and .annotation. This code doesn’t compile. The element (subelement of ) set to “false” forces the container to make the request for the servlet respond with HTTP Code 503 (Service unavailable).xml and web-fragment.http.

nullhaus.nullhaus. Considering the following web fragments ( attributes intentionally removed): <web-fragment> <servlet> <servlet-name>NullHaus Servlet</servlet-name> <servlet-class>com.NullServlet</servlet-class> <init-param> <param-name>myParam</param-name> <param-value>test2</param-name> </init-param> </servlet> </web-fragment> What will be the result of the request made to the following servlet: package com.nullhaus. d. 42. name="NullHaus Servlet") public class NullServlet extends HttpServlet { . The web fragment is merged into the final Deployment Descriptor before the web fragment related annotations are processed. The web fragment is merged into the final Deployment Descriptor after the web fragment related annotations are processed. e. The doesn’t have an subelement. All web fragments are processed together (in a batch) and all are merged into the final Deployment Descriptor before the web fragments’ related annotations are processed.c. f.NullServlet</servlet-class> <init-param> <param-name>myParam</param-name> <param-value>test1</param-name> </init-param> </servlet> </web-fragment> <web-fragment> <servlet> <servlet-name>NullHaus Servlet</servlet-name> <servlet-class>com. // necessary imports goes here @WebServlet(urlPatterns={"/foo/*"}.

println(myParam).nullhaus. **Consider the following testJar.initializer. The servlet code will not compile. a.class is a class which properly implements ServletContainierInitializer interface. b. test1. Init params with different names. b. test2.public void doGet(HttpServletRequest req. defined in annotations and in the Deployment Descriptor are additive (all init params will be present in the final Deplyment Descriptor). url-patterns with different values. c. d. If servlet A defines init param named PARAM through annotations.servlet. g. The web fragments are invalid and the application will not be deployed.jar structure: /META-INF/services/javax. null. **43.class Assuming that: • • MyInitializer.ServletContainierInitializer file consists of the following content: com. HttpServletResponse resp) { String myParam = getInitParameter("myParam"). c. the Deployment Descriptor value has precedence. test2. the annotation value has precedence. d.servlet. **44.getWriter(). This is an incorrect usage of JAR Services API for the a. b. but the order of these values is unspecified. h. f. javax. If servlet A defines init param named PARAM through annotations.MyInitializer Choose the statements which are true: This is a correct usage of JAR Services API for the ServletContainierInitializer. resp. } } test1. and servlet B defines init param named PARAM through the Deployment Descriptor. test1.initializer. e. defined in annotations and in the Deployment Descriptor are additive (all url patterns will be present in the final Deplyment Descriptor). test1 and test2. . and servlet B defines init param named PARAM through the Deployment Descriptor. **Choose the true statements about the Deployment Descriptor and annotations: a. test2.ServletContainierInitializer /com/nullhaus/MyInitializer.

html request invocation. **46.servlet. The MyInitializer class will be invoked if the testJar. **45.jar will be put somewhere in the web application classpath.html is accessible by /myApp/testJar/index0. The resource index2.jar will be put in the web application WEB-INF/lib directory. The resource index2. d.forward.forward. b. Some or all of the above request attributes are valid if the word “forward” will be replaced with “async”.servlet.html request invocation.html request invocation.html Assume that this testJar.html /META-INF/resources/index3. The MyInitializer class will be invoked if the testJar.html /META-INF/index2. The resource index1. Some or all of the above request attributes doesn’t have to be set by the container during request forwarding using RequestDispatcher#forward(-) method. b. a.path_info javax. Which statements are true: a.html is accessible by /myApp/testJar/resources/index1.html request invocation. c. d.html is accessible by /myApp/index2.query_string These are all valid request attributes which must be set by the container after the request is forwarded using RequestDispatcher#forward(-) method. The resource index1. The resource index0.html request invocation.jar structure: /index0.html is accessible by /myApp/testJar/index2.html request . e.forward.forward.html /resources/index1. **Which statements are true about the following request attributes: javax. The resource index0.html is accessible by /myApp/resources/index1.forward. c. f.request_uri javax. Some or all of the above request attributes are always holding the original request information even if multiple forwarding operations were made. Some or all of the above request attributes are valid if the word “forward” will be replaced with “include”. **Consider the following testJar.html is accessible by /myApp/index0.servlet.context_path javax.servlet. d.jar is placed under the “myApp” web application WEB-INF/lib directory. ServletContainerInitializer.servlet.c. e.servlet_path javax.

io.nullhaus. c.0: a.servlet. Security constraints can be managed programmatically. All listeners can be registered within the Deployment Descriptor. The resource index3. h.Dynamic#setServletSecurity(-) method.html is accessible by /myApp/index3. d. **Which statements are true about the listeners in Servlets 3. The resource index3. a default. import import import import javax.0 Security. c. no argument constructor. **49.*. Every listener implementor must not provide any constructor. java. Every listener implementor must provide a public. using ServletRegistration.0: a. which statements are true: a. **48.servlet. The @WebServletSecurity annotation have three attributes: value. compiler generated one should be created. The web. Security constraints can be managed through Deployment Descriptor. The web. d. **Considering Servlets 3.html request invocation.*. b.*. **Which statements are true about the web applications created with Servlets 3. b. Security constraints can be managed using @WebServletSecurity annotation. d.http. javax. javax. The listeners are invoked in the order in which they were registered. httpMethodConstraints and rolesAllowed.html request invocation. b.xml file is required.annotation.servlet.ServletSecurity.html is accessible by /myApp/testJar/resources/index3. invocation.annotation. The WEB-INF/ directory is not required. The WEB-INF/ directory is required.xml file is not required.g. . **50. **47. c.*. **Consider the following Servlet code: package com.

This servlet is accessible for all users. c. This servlet is accessible for all users. javax. @ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic. . javax.*. **Consider the following Servlet code: package com.getWriter(). httpMethodConstraints = {@HttpMethodConstraint( methodName = "GET".*.io. b.DENY is not a valid @HttpConstraint main (“value”) attribute value.servlet.DENY). c.print("Howdy Stragers!"). d. **51. import import import import javax. A runtime exception will be thrown while trying to access the servlet. b.servlet. The above code doesn’t compile. The EmptyRoleSemantic. e.DENY is not a valid @HttpConstraint main (“value”) attribute value. java. e.servlet.annotation. HttpServletResponse resp) throws IOException { resp.getWriter().DENY) @WebServlet(value = "/foo/*".ALLOW)}) @WebServlet(value = "/foo/*". A runtime exception will be thrown while trying to access the servlet. The EmptyRoleSemantic. } } Choose statements which are true about the GET HTTP request made to the NullServlet: a. HttpServletResponse resp) throws IOException { resp.@HttpConstraint(EmptyRoleSemantic. } } Choose statements which are true about the GET HTTP request: a. emptyRoleSemantic = EmptyRoleSemantic.print("Howdy Stragers!"). This servlet is not accessible for any users. d.http.ServletSecurity. The above code doesn’t compile.annotation. This servlet is not accessible for any users. name = "NullServlet") public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req.nullhaus. name = "NullServlet") public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req.*.*.

annotation. rolesAllowed. httpMethodConstraints = { . **53. d. java.servlet.annotation. c. transportGuarantee = TransportGuarantee.nullhaus.CONFIDENTIAL).http.**52.DENY. The above code doesn’t compile.*. which statements are true: a. name = "NullServlet") public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req. httpMethodConstraints = {@HttpMethodConstraint(value = "GET". A runtime exception will be thrown while trying to access the servlet. **Considering the following security constraints. This servlet is not accessible for any users. The default value for @HttpMethodConstraint#emptyRoleSemantic is EmptyRoleSemantic#DENY.DENY). HttpServletResponse resp) throws IOException { resp. @ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic. b. Valid @HttpMethodConstraint attributes are: value. The EmptyRoleSemantic. emptyRoleSemantic = EmptyRoleSemantic. javax. which statements are true: @ServletSecurity( value = @HttpConstraint( value = EmptyRoleSemantic.CONFIDENTIAL. **54. **Considering Servlets 3.*.io. transportGuarantee and emptyRoleSemantic. The default value for @HttpConstraint#transportGuarantee is TransportGuarantee.servlet.*. e. Valid @HttpConstraint attributes are: value.servlet. rolesAllowed and transportGuarantee. c. } } Choose statements which are true about the servlet’s HTTP GET request: a.DENY is not a valid @HttpConstraint main (“value”) attribute value.ServletSecurity.getWriter(). d. b. javax.0 security constraints annotations.*. import import import import javax. This servlet is accessible for all users. **Consider the following Servlet code: package com.PERMIT)}) @WebServlet(value = "/foo/*".print("Howdy Stragers!").

*. For GET HTTP method request. @HttpMethodConstraint( value = "POST". f. c. not Servlet 3.*.annotation. For all HTTP methods and for all roles. This annotation defines a security role link for the “Barbra” role within the “MyBarbra” servlet. This annotation is defined in Common Annotations.io. This annotation is equal to the following DD fragment: <web-app . a.security.nullhaus. c. import java. e. For POST HTTP method request. For POST HTTP method request. access to this servlet is forbidden and the confidential transport is required.. import javax. the access to this servlet is allowed with no further roles restrictions.PERMIT) } ) @WebServlet("/foo") public class MyServlet extends HttpServlet { } For all HTTP methods other than GET and POST. d. the access to this servlet is forbidden if the role is different than “manager”. choose statements which are true: package com.http.@HttpMethodConstraint( value = "GET". **55.. b. import javax. access to this servlet is forbidden and the confidential transport is required.> <security-role> <role-name>Barbra</role-name> </security-role> </web-app> a. and for all roles. @DeclareRoles("Barbra") public class MyBarbra extends HttpServlet { } This annotation defines a security role “Barbra” for the “MyBarbra” servlet. d. . **Considering the following servlet code.0. rolesAllowed = "*". For GET HTTP method request. This is an invalid usage of @DeclareRoles annotation. e. emptyRoleSemantic = EmptyRoleSemantic. the access to this servlet is forbidden if the role is different than “manager”. the access to this servlet is forbidden if the role is equal to “manager”. rolesAllowed = "manager"). b.servlet.*.

I’m leaving! Bye!.startAsync(). ServletResponse) method. . is not necessary and can be safely removed. There is no HttpServletRequest#startAsync() method – there is only a HttpServletRequest#startAsync(ServletRequest. @WebServlet(urlPatterns = "/foo/*". } } This code compiles and runs fine. The guaranteed order of texts printed in the console/log file is: I’m inside!.start(new Runnable() { public void run() { System. choose which statements are true after a GET request is made: package com.servlet.*. name="NullServlet") public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req. A runtime exception will be thrown when accessing this servlet.annotation. } }). b.out. Considering the following asynchronous servlet code. final AsyncContext ac = req. HttpServletResponse resp) { System. ac. The modifier “final” in final AsyncContext ac = req. f.startAsync(). e. System.out.println("*** I'm an async thread!").56. c. ac. d. import javax.out.servlet. This code doesn’t compile.*. import javax. *** I’m an async thread!.*.nullhaus.complete().http.println("I'm inside!").println("I'm leaving! Bye!"). a. import javax.servlet.

import javax. . ServletResponse) method. @WebServlet(urlPatterns = "/foo/*".*. final AsyncContext ac = req. name="NullServlet". c.startAsync(). d.servlet. HttpServletResponse resp) { System.out. System. ac. *** I’m an async thread!.out.http.nullhaus. b.*. There is no HttpServletRequest#startAsync() method – there is only a HttpServletRequest#startAsync(ServletRequest. The guaranteed order of texts printed in the console/log file is: I’m inside!. } } This code compiles and runs fine. a. I’m leaving! Bye!. g.servlet. choose which statements are true after a GET request is made: package com. ac.startAsync(). **Considering the following asynchronous servlet code.out.start(new Runnable() { public void run() { System. e.servlet.annotation. f. There is no “asyncSupported” attribute of @WebServlet. The modifier “final” in final AsyncContext ac = req.println("I'm inside!"). is not necessary and can be safely removed. asyncSupported = true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req. } }). This code doesn’t compile.**57.*.complete().println("I'm leaving! Bye!"). import javax. A runtime exception will be thrown when accessing this servlet. import javax.println("*** I'm an async thread!").

b.startAsync().start(new Runnable() { public void run() { ac.html” will be served as a response. A runtime exception will be thrown when accessing this servlet.complete().*.servlet.servlet.http.html"). import javax. . name = "NullServlet". This code doesn’t compile. choose which statements are true after a GET request is made: package com.annotation.nullhaus.dispatch("/page.**58. } This code compiles.servlet. asyncSupported = true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req. The content of “/page. **Considering the following asynchronous servlet code. import javax. } a. } }). d. HttpServletResponse resp) { final AsyncContext ac = req. import javax. ac. @WebServlet(urlPatterns = "/foo/*". c. ac.*.*.

name = "NullServlet". d.*.*. Considering the following asynchronous servlets code.http. choose which statements are true after a GET request to the NullServlet is made: package com. @WebServlet(urlPatterns = "/foo/*". This code doesn’t compile. import javax.*. @WebServlet(urlPatterns = "/baz/*". A runtime exception will be thrown when accessing this servlet.servlet.*.*. . } } a.servlet. HttpServletResponse resp) throws IOException { resp.servlet.io.59.http.nullhaus.println("Howdy from NullServlet2!").*.servlet.println("Howdy from NullServlet1!").annotation. import javax. asyncSupported = true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req.*. The “Howdy from NullServlet1″ will be included in the response. import java.getWriter(). import javax.annotation.getWriter().servlet. final AsyncContext ac = req. HttpServletResponse resp) throws IOException { resp.start(new Runnable() { public void run() { ac. e.io. import javax. The “Howdy from NullServlet2″ will be included in the response. import java. } } package com.*. This code compiles. b. asyncSupported = false) public class NullServlet2 extends HttpServlet { public void doGet(HttpServletRequest req.dispatch("/baz"). c.startAsync(). import javax. ac. import javax.servlet. name = "NullServle2". } }).nullhaus.

import javax. choose which statements are true after a GET request to the NullServlet2 is made: package com.io.getWriter(). import javax.println("Howdy from NullServlet1!").servlet.println("Howdy from NullServlet2!").*. import javax. This code compiles. **61.io. The “Howdy from NullServlet2″ will be included in the response. c.http. b. **Considering the following Asynchronous Servlets code.annotation.*. } } a.*. import javax.servlet. @WebServlet(urlPatterns = "/foo/*". This code doesn’t compile. import java. .nullhaus. name = "NullServle2". req. asyncSupported = true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req.**60. ServletException { resp.getRequestDispatcher("/foo"). import java. d.*.*.*.nullhaus.getWriter(). import javax. HttpServletResponse resp) throws IOException { } } package com.forward(req.nullhaus.*. HttpServletResponse resp) throws IOException. resp.servlet.servlet.io.servlet. asyncSupported = false) public class NullServlet2 extends HttpServlet { public void doGet(HttpServletRequest req. choose which statements are true after a GET request to the NullServlet2 is made: package com. **Considering the following Asynchronous Servlets code. The “Howdy from NullServlet1″ will be included in the response. resp). import javax. A runtime exception will be thrown when accessing this servlet. import javax.*.http.servlet.annotation. @WebServlet(urlPatterns = "/baz/*". e. import java. name = "NullServlet".*.servlet.*.

A runtime exception will be thrown when accessing this servlet. The “Async!” will be included in the response.*.println("Async!").*.annotation. b.servlet. import javax. name="NullServle2".println("Howdy from NullServlet1!"). ac. final AsyncContext ac = req.io. The “Howdy from NullServlet2″ will be included in the response. import javax.start(new Runnable() { public void run() { System.startAsync().servlet. d. f. e. import java.annotation.import javax. 62. .getWriter(). choose which statements are true after a GET request to the servlet is made: package com.*.*. asyncSupported = true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req.forward(req. } } req.nullhaus. ServletException { resp. @WebServlet(urlPatterns = "/foo/*". HttpServletResponse resp) throws IOException { resp. ac. HttpServletResponse resp) throws IOException.*. Considering the following Asynchronous Servlet code. resp).servlet.nullhaus.getWriter(). name = "NullServlet". import javax.servlet. The “Howdy from NullServlet1″ will be included in the response.http. This code doesn’t compile.*. @WebServlet(urlPatterns = "/baz/*". import javax. This code compiles. a. c.out. } }).servlet.println("Howdy from NullServlet2!").getRequestDispatcher("/foo").complete(). asyncSupported=false) public class NullServlet2 extends HttpServlet { public void doGet(HttpServletRequest req.http. } } package com.

import javax. ac.*.startAsync(). try { PrintWriter pw = ac. } catch (IOException e) { e.http.servlet. A runtime exception will be thrown when accessing this servlet. c.getRequest(). **63. e. b.io. This code doesn’t compile. name="NullServlet". import javax. asyncSupported=true) public class NullServlet extends HttpServlet { . import javax.io. ac. import javax. HttpServletResponse resp) throws IOException { req.getWriter().nullhaus. import javax. The asynchronous operation will be never timed out.*. choose which statements are true after a GET request to the NullServlet is made: package com.*. } }).start(new Runnable() { public void run() { String att = (String)ac.complete().annotation.http.servlet. d. @WebServlet(urlPatterns = "/foo/*".getAttribute("Hello"). } ac.setTimeout(-2).import java.*. pw.printStackTrace(). import javax. The “Async! Value of Hello is: null” will be included in the response. g. "World"). The asynchronous operation will be timed out after the server default timeout value.annotation. The “Async! Value of Hello is: World” will be included in the response. f.*.*. import java. **Considering the following Asynchronous Servlets code.servlet.servlet. name="NullServlet". } } a.servlet.*. @WebServlet(urlPatterns = "/foo/*".*. final AsyncContext ac = req.getResponse(). asyncSupported=true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req.println("Async! Value of Hello is: " + att).setAttribute("Hello".servlet. This code compiles.

servlet. ServletException { if (req. @WebServlet(urlPatterns = "/baz/*". The request will be served fine.*. import javax.getDispatcherType() == DispatcherType.servlet. The “Value of Hello is: World” will be included in the response. resp).*.getRequestDispatcher("/baz").http. 64. import java. c. import javax. a.http.ASYNC) { String hello = (String)req. f. d.setAttribute("Hello".REQUEST) { req.annotation.dispatch(). name="NullServlet2".*. name="NullServlet".servlet.*.nullhaus.getWriter().servlet. final AsyncContext ac = req.servlet. HttpServletResponse resp) throws IOException.public void doGet(HttpServletRequest req.println("Value of Hello is: " + hello).*. A runtime exception will be thrown when accessing this servlet. that was a ride!"). } else if (req.getWriter().*.*.getDispatcherType() == DispatcherType. import javax.servlet. resp. asyncSupported=true) public class NullServlet2 extends HttpServlet { public void doGet(HttpServletRequest req. asyncSupported=true) public class NullServlet extends HttpServlet { . The “Value of Hello is: null” will be included in the response. g.io.forward(req.*.annotation. import javax.println("Phew.io. b. } } } package com. The inifite loop dispatch-loop will be created. import javax. "World"). ac. HttpServletResponse resp) throws IOException { req.nullhaus. } } This code compiles. This code doesn’t compile. @WebServlet(urlPatterns = "/foo/*". e. but no text will be included in the response. import java. import javax. resp.startAsync(). Considering the following Asynchronous Servlets code. choose which statements are true after a GET request to the NullServlet is made: package com.getAttribute("Hello").

*.REQUEST) { . HttpServletResponse resp) throws IOException.*. d.getDispatcherType() == DispatcherType.*. import javax. import java. f.http. but no text will be included in the response. asyncSupported=true) public class NullServlet2 extends HttpServlet { public void doGet(HttpServletRequest req. c.servlet. ServletException { if (req. This code doesn’t compile.*.startAsync().servlet. import javax. import javax.public void doGet(HttpServletRequest req. HttpServletResponse resp) throws IOException.annotation.servlet.getWriter(). ac. } } a. choose which statements are true after a GET request to the NullServlet is made: package com.dispatch("/foo").http. Considering the following Asynchronous Servlets code. name="NullServlet2".servlet.*. HttpServletResponse resp) throws IOException { AsyncContext ac = req. @WebServlet(urlPatterns = "/baz/*".servlet.nullhaus.ASYNC) { resp.nullhaus. } else if (req. The inifite loop dispatch-loop will be created.REQUEST) { AsyncContext ac = req.annotation. e. asyncSupported=true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req. import javax.io. ac.io. name="NullServlet". This code compiles. 65. import java.getDispatcherType() == DispatcherType.*.dispatch("/baz").println("Shotgun!"). The request will be served fine. A runtime exception will be thrown when accessing this servlet. import javax.*.servlet. import javax. @WebServlet(urlPatterns = "/foo/*". b.getAsyncContext(). ServletException { if (req. } } } package com.*. The “Shotgun!” will be included in the response.getDispatcherType() == DispatcherType.

out.servlet.out.nullhaus. import javax.*.ASYNC) { resp.startAsync().println("#Async listener [onTimeout]").dispatch("/baz").startAsync(). import javax.*.*. The inifite loop dispatch-loop will be created.*.io.getWriter(). but no text will be included in the response.http. } else if (req. @WebServlet(urlPatterns = "/baz/*". A runtime exception will be thrown when accessing this servlet.servlet. asyncSupported=true) public class NullServlet2 extends HttpServlet { public void doGet(HttpServletRequest req. import javax. } } } package com. This code doesn’t compile. ac.annotation.AsyncContext ac = req.*. import java.println("#Async listener [onError]").println("#Async listener [onStartAsync]").println("#Async listener [onComplete]"). The request will be served fine. a. } . f. c.nullhaus. ** *|||*For questions 66 and 67 assume that the MyListener class is defined as follows: package com. } public void onStartAsync(AsyncEvent event) { System.servlet.annotation. import javax. import javax. } public void onError(AsyncEvent event) { System.servlet.http.getDispatcherType() == DispatcherType.dispatch("/foo").servlet. } } This code compiles. } public void onTimeout(AsyncEvent event) { System. HttpServletResponse resp) throws IOException { AsyncContext ac = req.*. name="NullServlet2". ac. e.out.out. import javax.println("Shotgun!"). The “Shotgun!” will be included in the response.servlet. @WebListener public class MyListener implements AsyncListener { public void onComplete(AsyncEvent event) { System. d. b.*.

servlet. name="NullServlet". AsyncListener al = ac.complete(). c. import javax. import javax. This code compiles. A runtime exception will be thrown when accessing this servlet. The “#Async listener [onStartAsync]” message will be to the console/log file.servlet. asyncSupported=true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req.nullhaus. try { Class lClass = Class. @WebServlet(urlPatterns = "/foo/*".addListener(al).servlet.start(new Thread() { public void run() { ac. 67. HttpServletResponse resp) throws ServletException { final AsyncContext ac = req.servlet. name="NullServlet".*. The “#Async listener [onError]” message will be to the console/log file. } catch (ClassNotFoundException e) { e. @WebServlet(urlPatterns = "/foo/*". f. import javax. What will be the result of the first GET request to the following servlet: package com.forName("com.annotation.http.createListener(lClass). This code doesn’t compile. import javax. d. b. } ac. **What will be the result of the **first GET request to the following servlet: package com. g. } } a.servlet.MyListener"). e.http. The “#Async listener [onTimeout]” message will be to the console/log file.nullhaus.} 66. .*.startAsync().nullhaus.printStackTrace().servlet.*. ac. } }).*.annotation. The “#Async listener [onComplete]” message will be to the console/log file. import javax. import javax.*.*.

The “#Async listener [onComplete]” message will be to the console/log file.MyListener").printStackTrace().sleep(5000). c.forName("com. ac. A runtime exception will be thrown when accessing this servlet.complete(). The “#Async listener [onStartAsync]” message will be to the console/log file. g. } catch (InterruptedException e) { e. . ac. This code compiles. } } a. The “#Async listener [onTimeout]” message will be to the console/log file. The “#Async listener [onError]” message will be to the console/log file.createListener(lClass). try { Class lClass = Class.start(new Thread() { public void run() { try { this.addListener(al).asyncSupported=true) public class NullServlet extends HttpServlet { public void doGet(HttpServletRequest req. HttpServletResponse resp) throws ServletException { final AsyncContext ac = req.setTimeout(3000). d.printStackTrace().nullhaus. } ac. e.startAsync(). } ac. b. } catch (ClassNotFoundException e) { e. f. This code doesn’t compile. AsyncListener al = ac. } }).

4. d Reference: page 72. as well as instantiate all of them. If you need to define the ordering. the resulting parameter values list will consists of the query string values.xml.3 “Assembling the descriptor from web. Otherwise. the PathInfo part of the request path is the part which doesn’t belong to the ContextPath nor the ServletPath and ends before the query string. the resulting parameter values list will consists of the query string values. 3. c. 5. d.1 “HTTP Protocol Parameters” Explanation: When the same variable name exists in the query string. Basically.4 “Configuration methods” Explanation: Programmatic addition of servlets / filters can be achieved only when the ServletContext is not fully initialized. you’ll get a big.2.0 allows you to programatically add servlets. 4.) and works basically on the order of listeners definition in the DD. the IllegalStateException will be thrown. c.xml and annotations”. 3. This can be achieved from within the ServletContextListener or the ServletContainerInitializer. d Reference: page 22. webfragment. After it’s initialization. b. you should use the Deployment Descriptor which follows a set of rules (defined in section 8. d Reference: page 25.2. **4. e.1 “HTTP Protocol Parameters” Explanation: When the same variable name exists in the query string. Explanation: The order of listeners when using @WebListener annotation is unspecified. d Reference: page 30. filters. 3. f . 3.3. followed by the POST data. as well as in the POST body. g Reference: pages 30 – 35**. as well as in the POST body.Answers 1. e** *|||* Reference: page 22. a. section 8. followed by the POST data. 6. c. 2. listeners. fat IllegalStateException. . 2. TheHttpServletRequest#getParameter(-) returns only the first parameter value.4 “Configuration Methods” Explanation: Servlets 3.5 “Request Path Elements” Explanation: The “/security” mapping doesn’t have any restriction policy. However mind that you can do this only when the ServletContext is not initialized.

5 “ServletRegistration getServletRegistration(String servletName)” Explanation: You can access already registered servlet.e. Therefore. d Explanation: There can’t be a duplication of filter name in the Deployment Descriptor.4. 7. d Explanation: There can’t be a duplication of filter name in the Deployment Descriptor. no matter how it was registered using the ServletContext#getServletRegistration(-). However. 8. c Reference: page 32. There is no difference if the filter class is different or not. The HttpSessionActivationListener and HttpSessionBindingListener are listeners related to the particular object and as-is doesn’t need to be registered at all.The nor the loadOnStartup @WebServlet annotation attribute doesn’t have any effect in this case. there is a special case when ServletContextListener can be programmatically registered – it’s when the ServletContext is obtained from the ServletContainerInitializer#onStartup() method. Reference: page 37.4 “Configuration of Filters in Web Application” Explanation: If the programmer will define two filters with the same filter class. the container is enforced to create two instances of the filter.2 “@WebFilter” Explanation: The default @WebFilter name (if not defined through the . 11.3 “Programmatically adding and configuring Listeners” Explanation: As said before. 10. b. d. 13. the source code of the test. the programmatically addition of listeners / servlets / filters can be made only before the ServletContext is fully initialized. 9. a. a. alter the url mapping paths for the particular servlet. This means that in common cases programmatic addition of ServletContextListener is useless. a. c Reference: page 49.1. 8. 4. 4.4. 6. c Reference: page 63. c.jsp file will be included as-is into the response. b. 12. You can obtain a ServletRegistration object which then can be used to i.2. There is no difference if the filter class is different or not.6 “Resources” Explanation: The ServletContext#getResource(-) method is not intented to be used for dynamic content but for static.1. 4. f Reference: page 34.

e Reference: page 53. c. . d. 20.5 “Filters and RequestDispatcher” Explanation: The special filter name “*” has been introduced to express that the request match either by the path or the servlet name should be passed to this filter. d. The filter mapping configuration lacks the … element. b. c.0 the new dispatcher type ASYNC has been introduced. 6. b Explanation: If the @WebFilter name is specified. 6.xml is a part of a JAR file.2.xml and web-fragment. In Servlets 3. g Reference: page 65. 8. It is a valid value of the element and servletNames attribute.2.2.1 “Modularity of web. 18.5 “Filters and the RequestDispatcher” Explanation: The correct answer is a set of 5 valid RequestDispatcher types. If this web-fragment. Moreover.2. 8. f Reference: page 52. a Reference: page 50. 6. the exception will not be thrown and the container will initialize only one instance of the filter.nullhaus.xml” Explanation: The order of web fragments discovery can be defined only if the ordering rules ( or ) are defined in the Deployment Descriptor. a. a. the values specified in the annotation will be added to the attributes defined in the DD. and it’s the same as the DD one. so c is incorrect. so RequestDispatcher operations will not pass the filter.NullFilter in this case).xml“. Therefore. 16. From the logical point of view.xml” Explanation: The name of the web fragment descriptor is “web-fragment. there is only one Filter named “MyFilter 1″ with url-patterns “/*”.4 “Configuration of Filters in Web Application” Explanation: There can be multiple and elements in one element. e Reference: page 66. 19. there are two differently named filters which refers to the same class. which means that first the url-pattern hits are executed in the order in which they appear in DD** followed by **the hits are executed in order in which they appear in the DD. 17. so b is incorrect. a Explanation: The wildcard matches all requests made to the web application.filterName attribute of the annotation) is fully qualified class name (com. 15. 14. it must be located under JAR’s META-INF/ directory.2 “Ordering of web. The order of such combination of elements is standard.2.

xml and web-fragment.xml” Explanation: If the metadata-complete attribute is present in the web.2.xml. . 8. 8.xml and it is set to true. the fragment will not be added to the result DD.2 “Ordering of web.2 “Ordering of web.xml” Explanation: If the metadata-complete attribute is present in the webfragment.xml and web-fragment. 8. The metadata-complete attribute of the element in web. It cannot be defined within the web-fragment. it must be located under application’s WEB-INF/lib directory.xml and web-fragment. which means that** the container will scan** for web-fragments that can be combined into final Deployment Descriptor.2 “Ordering of web. but is not required to discover web fragments which are not located under WEB-INF/lib.2.xml” Explanation: The element can only be present in the web.xml” Explanation: When the element is present in the web. e Reference: page 66.xml is a part of a JAR file and it’s supposed to alter or contribute to the final Deployment Descriptor. it informs the container that the particular web fragment is complete and no annotations related with this web fragment should be scanned.xml and it is set to true.2. The container can.xml and web-fragment. 21.xml file. a Reference: page 66.xml files should be scanned. Therefore no web-fragment.xml files should be scanned and the annotations should be combined into the final DD. 25. The element defines that every web fragments which are not defined explicitely within the element. will be automatically added by the container to the result DD.xml” Explanation: If the element is present in the web.xml. and no annotations should be taken under consideration.xml is by default set to false.2 “Ordering of web.2.xml and web-fragment. it informs the container that the whole Deployment Descriptor data is complete and is presented in the web. it takes under consideration only the fragments which are specified by the … element. h Reference: page 66. 24. 22. it defines the effective order of the web-fragments. 8. The default value of the metadata-complete attribute is false which means that both the web-fragment. 8. Any occurences of element within the webfragment. a Reference: page 66. 23. If the fragment name is not present within the … element and the element is not present.xml.2 “Ordering of web.xml will be ignored.If this web-fragment. g Reference: page 67.2.xml.

xml is incomplete. this attribute takes value false. The only difference here is that the “value” attribute is used explicitely in the @WebServlet annotation.1 “@WebServlet” Explanation: The only catch in this example is that the NullHausServlet has a . but none of the methods are abstract. 8. a. which can be used to determine if the data presented in the web. c Reference: page 61. 8.xml has a different behaviour than the same attribute within the web.1 “@WebServlet” Explanation: There is a @WebServlet annotation. so f is incorrect. the e and a are incorrect. So.1. The @WebServlet annotation defines two ways of specifying url-pattern for the annotated Servlet – directly into the @WebServlet annotation (as in the example – implicitely using value attrbute) or using an urlPatterns attribute. which means that the annotations for the particular web fragment will be scanned. but — however — is no different than specifying the value implicitly as in the @WebServlet(“nullHausServlet”) construct. 27.Note that the metadata-complete within the web-fragment.xml files and for annotated classes to form the effective. The url-pattern should start with “/”. the url-pattern is still invalid. If the data presented by the web. therefore b is incorrect. 8. so this url-pattern is invalid. as the HttpServlet is an abstract class. 26.1 “Annotations and pluggability” Explanation: The metadata-complete is a and elements attribute.xml is complete (“true”) or incomplete (“false”). therefore empty class implementation is perfectly valid. the container will scan for additional web-fragment.1. c Reference: page 62. 29. Deployment Descriptor.xml file! The default value for metadata-complete is false. so d is incorrect.xml files as well as any used annotations. 28. If the value is set to “false” the container will ignore any web-fragment. f Reference: page 62.1 “@WebServlet” Explanation: For the main explanation. final. and if it would be @WebServlet(value = “/nullHausServlet”) it would be correct. Check the exemplary code provided for this question in the bundle at the end of this test. This is perfectly valid. e. refer to the previous question. 8. So. c Reference: page 62. This code compiles fine. b.1. By default.

as each container may decide what policy it will follow.1 “@WebServlet” Explanation: When the same servlet class — but with different name — is . If the url-pattern is defined in both: the DD and the annotations. Also note that even that the urlPatterns operates on String array.e.1 will not throw any exceptions unless you try to access the servlet (i. b. 34. The servlet will not be deployed and will not be accessible even by the name from the DD. 8. which makes the Servlet useless for the container. 31. 8. the container is not required to create a new instance of the servlet class.xml and annotations” Explanation: When the same servlet class is defined in the DD with the same name.1 “@WebServlet” Explanation: One of the urlPatterns or value attributes are required. However. as some kind of servlet-pools are allowed to be present. the container is forced to create a new instance of the servlet class.xml.1. The specification suggest using the default value attribute.1. 32. c Reference: page 62. 30.1. which you pass as a value. the exact number of servlet instances is undefined.1. c Reference: page 62. however the exact number of servlet instances is unpredictable and it’s container-dependent. c. 8. when this is the only attribute in the annotation.b Reference: page 62. using its name).3 “Assembling the descriptor from web. but only one of them can be present in the @WebServlet annotation. web-fragment.1. 33.1 “@WebServlet” Explanation: The urlPatterns and value attributes are required.1 “@WebServlet” Explanation: When the same servlet class is defined in the DD with another name. you can define only one String element.2. 8. 8. a. 8.package (default) access modifier. d Reference: page 62.1 “@WebServlet” and page 81. The default name of the servlet — if it’s “name” attribute is not specified — is a fully-qualified class name. and url-patterns if there are more attributes in the annotation. Note that both Tomcat 7 and GlassFish Server 3. f Reference: page 62. the DD takes precedence.

8.1. 39. 8. 35. . f.1. 38.1. and the programmatic one will have its own configuration.** the container will create two instances of the servlet**.xml file. the behaviour is not specified. Tomcat 7 and Glassfish 3. 37. 36.servlet. because there is a annotation duplication error.0. g Reference: page 69. Rasin 4. If it’s used as a direct annotation of the servlet class.1 “@WebServlet” Explanation: When the servlet is programmatically created using the same name as previously defined (using annotations or DD).1 (both uses Catalina servlet container implementation) will throw NullPointerException — ctx. The annotated one will have configuration as defined using the annotations.16 will create one instance of the servlet and add the two urlpatterns.xml) is the place where this element must be placed.3 “@WebInitParam” Explanation: The @WebInitParam defines the servlet config init param which is correctly accessed in this code (HttpServlet#getInitParameter(-) is in fact an invocation of getServletConfig().1 “@WebServlet” Explanation: Classes annotated with @WebServlet annotation must extend the javax. so the single servlet instance will respond to both: /baz/* and /foo/* url patterns. it will not have any impact.getInitParameter(-)). 8. c. A concrete Java annotation cannot be used more than once in a single class.3 “@WebInitParam” Explanation: The @WebInitParam must be used as a @WebServlet‘s initParams attribute value. The element is used to define an absolute ordering of web fragments and the main DD (web. f Reference: page 63.1.addServlet(-) returns null and none of the url patterns will be mapped to the servlet. 8. a Reference: page 63. b Reference: page 62.xml and web-fragment.instantiated using programmatic addition. 8. c Reference: page 63. b.HttpServlet class.2.xml” Explanation: The element is used to define a relative ordering of web fragments and it’s possible location is within the web-fragment. 8.2 “Ordering of web.1. 40.3 “@WebInitParam” Explanation: This code doesn’t compile. b Reference: page 62.http.

so the init-params with the same name. If this filename would be corrected.2 “Using a Request Dispatcher” Explanation: The Servlets 3. 42.0 brings new set of request attributes which are set after dispatching the asynchronous processing using AsyncContext#dispatch(-). b Reference: page 84. webfragment.xml. 8. a. a. c. option d would be also correct. Therefore. 9.2.3 “Assembling the descriptor from web. Each web fragment is processed separately.ServletContainerInitializer. The container will firstly process the particular web fragment (web-fragment. It will result in an application deploy failure. 8. c Reference: page 81. . 8. If the url-pattern is defined in the DD it replaces the urlPatterns annotation for the particular servlet.3 “Assembling the descriptor from web. The only valid elements are and which can have or subelements. 43. the container will process the next web fragment.xml and annotations” Explanation: Basically.xml and annotations” Explanation: The element set to “false” forces the container to disable the specified servlet.2. d Reference: page 73. just as option d suggests. than it’ll process this web fragment annotations and only after this. The init params with different names are additive in the final DD.xml. The container doesn’t have to run initializer which is in a JAR file in the web application classpath but not in the WEBINF/lib. defined in DD has precedence over the ones defined in annotations and will replace them. It should be javax. 8. 45. 41.xml). d. a. the f option is incorrect.3 “Assembling the descriptor from web. 44.xml. e Reference: pages 90 – 95.2.2. which means that the defined will not forward the request to the servlet. the DD has precedence over the annotations.The is not a valid subelement of element. webfragment. webfragment. These attributes replaces the “forward” word in the above example with “async“.xml and annotations” Explanation: The situation in which two different web fragments defines the same name of a but with different values is as a configuration conflict.servlet. g Reference: page 74.4 “Shared libraries / runtimes pluggability” Explanation: The service file is incorrectly named.

3 “Listener Class Configuration” Explanation: Every listener class must provide a public. to static resources which are located in the** /META-INF/resources** directory of a JAR file located in WEB-INF/lib directory of the web application. a Explanation: This might seem like a valid Http constraint which denies access for all users. This is because the @HttpConstraint and @HttpMethodConstraint can be used only as the @ServletConstraint annotation attributes. 51. b Reference: page 122. 48. b. no argument constructor. Hence. The rolesAllowed attribute is a part of @HttpConstraint or @HttpMethodConstraint. however. doesn’t have to contain neither the WEB-INF directory. h Reference: page 99. The @ServletSecurity annotation has two attributes – value and httpMethodConstraint. Such resources are served directly to the client. programmatically.13 “Inclusion of a web. 13. 10. There is no requirement that this constructor must be compiler generated. annotations) of managing security constraints are valid. The AsyncListener cannot be registered in the DD – it must be registered programmatically. 11. e Explanation: There is no methodName attribute for @HttpMethodConstraint . not the @ServletSecurity. a. nor the web.All of those attributes always hold the information about the original request. 47.4 “Programmatic Access Control Annotations” Explanation: All three ways (DD. a. a runtime exception will not be thrown. 50. 10. d Reference: pages 111 – 112. but the annotation name is @ServletSecurity – not @WebServletSecurity.xml Deployment Descriptor” Explanation: An application which is serving only a static content. An exception is made. 46. 49. The HttpSessionActivationListener and HttpSessionBindingListener are not registered in the DD. but the servlet will act like there are no security constraints defined. The compiler wont’ complain. d Reference: page 107.xml file. but in fact it is inappropriate usage of @HttpConstraint annotation.5 “Directory Structure” Explanation: The WEB-INF directory in a web application is basically a private directory. the a and b are correct and c is incorrect.

15.4 “Programmatic Access Control Annotations” Explanation: The default value for @HttpConstraint#transportGuarantee is TransportGuarantee.1 “@DeclareRoles” Explanation: This is a valid usage of the @DeclareRoles annotation which defines a security role with name passed as the annotation value attribute.NONE. one should use the DD. a Explanation: This is the correct usage of the annotations. Tomcat 7. e Reference: page 181.a. you need to add the annotations-api.3.jar to your classpath. a . 56. c Reference: pages 123 – 126. The value should be used instead. you should not define emptyRoleSemantic when rolesAllowed list is not empty. 57. It is impossible to create a security role link using @DeclareRoles annotation.4 “Programmatic Access Control Annotations” Explanation: The value attribute defines the constraint which affects the HTTP methods which are not listed using the httpMethodConstraints attribute. a. or by true element in the DD. To do so. 13. 53.annotation. There is no EmptyRoleSemantic. when is used it means “all roles”. The default value for @HttpMethodConstraint#emptyRoleSemantic is EmptyRoleSemantic.3 “Asynchronous processing” Explanation: To use the Asynchronous Servlets features. d.5. it doesn’t. e Reference: pages 10 – 20. 54. The PERMIT value should be used instead.3. EmptyRoleSemantic defines the default action which should be undertaken if the rolesAllowed returns an** empty list** (no roles are defined). The servlet is allowed only for HTTP GET requests and blocked for all other HTTP methods requests despite the user’s role.PERMIT. 52. b Reference: pages 122 – 125. In the DD. but in the @ServletSecurity annotation.e. a. As a side not. the servlet must support this type of processing either by defining asyncSupported = true attribute of the @WebServlet. This annotation is defined in Common Annotations which means that if you’re using i. The “*” as a value of rolesAllowed attribute doesn’t have any special meaning. 2. 55. 13.ALLOW enum value.

but the exception throwing is delayed to the moment of actually using the asynchronous nature of the servlet – like AsyncContext.3.3. **59. as the request has already been dispatched. 2. 60. By using req.startAsync() the original request and response objects are passed to the asynchronous thread. this code explicitely uses the Asynchronous features.html”) and implicitely treat it like the AsyncContext#complete() method invocation.3 “Asynchronous processing” Explanation: It is illegal to dispatch the request from the synchronous servlet to the asynchronouse. The following ac. as the uncommited output in response buffer is cleared during the forwarding. b.3. 61. a. so the “Howdy from NullServlet1″ **will not be lost **and will be included in the response. 2.3 “Asynchronous processing” Explanation: This code runs fine – there is an asyncSupported attribute and in fact it’s the only asynchronous related attribute in the @WebServlet annotation. e Reference: page 14.3.3. e Reference: pages 11. Things like timeouts must be dealt programmatically by using the AsyncContext. 58.Reference: pages 10 – 20. the only guaranteed thing is that the “I’m inside” message will be printed first.3 “Asynchronous processing” Explanation: Refer to the previous question’s explanaition.3. 2. The “Howdy from NullServlet2″ will not be included in the response. 2.3. c Reference: pages 10 – 20.3. 2. it is legal to do such dispatch. The order of messages is not guaranteed. c Reference: pages 10 – 20. b. 62.3 “Asynchronous processing” .3 “Asynchronous processing” Explanation: It is fine to dispatch from an asynchronous servlet to the synchronous. and the Container/JVM can choose how and when execute them.3.3. c. 2.3 “Asynchronous processing” Explanation: The container will immediately dispatch the request to the given resource (“/page.startAsync(-).3. a. The modifier final is necessary.3. so the IllegalStateException will be thrown.complete() invoacation will result in a** runtime exception** — IllegalStateException — thrown. **a. because the “ac” variable must be accessible from the anonymous inner class. If the asynchronous servlet doesn’t use any of the asynchronousity features. c Reference: pages 11. a. There are two threads.

the listener onTimeout(-) method will be invoked. A runtime exception will be thrown. The timeout. 2. **a. e Reference: page 16.3 “Asynchronous processing” Explanation: It is illegal to use more than one asynchronous dispatch from one AsyncContext.3. **a. 2. c Reference: page 15. 2. the following AsyncContext#dispatch() will dispatch the to the URL of the original request (/foo/*).Explanation: If the AsyncContext#setTimeout(-) argument is <= 0.3 “Asynchronous processing” Explanation: After the given timeout. **a. **63.3.3.3 “Asynchronous processing” Explanation: It is illegal to use more than one asynchronous dispatch from** one AsyncContext**. as it’s illegal to complete the asynchronous processing** if the request has already been dispatched (timeout)**. **a. d. b Reference: page 16. The last thing shown is that the ServletRequest and the ServletResponse are the same objects in the dispatch chain. error and onStartAsync (it’s the first invocation of startAsync()) will not occur in this case.3.3. 2.complete() invocation). as well as the onError(-). it means that the asynchronous operation will** never be timed out**.3 “Asynchronous processing” Explanation: The listener will be notified after the asynchronous processing will be completed. e Reference: pages 17 – 18. b. 2.3 “Asynchronous processing” Explanation: This code is an example of how to use the ServletRequest#getDispatcherType() to recognize if the request was made initialy (REQUEST) or through asynchronous dispatch (ASYNC).3.startAsync() instead of req. After that. **67. but in this case a AsyncContext has been reinitialized (req. This invocation will be followed by the IllegalStateException.3. so the attributes set before asynchronous thread start are accessible from within the thread. f Reference: pages 17 – 18. The ServletRequest#startAsync() method uses the unwrapped ServletRequest and ServletResponse. so the attributes are saved properly. e. **64. **66. **65.3.3.getAsyncContext()). **a. the onComplete(-) method will be invoked (response for the ac.3. . Another thing is that if the unwrapped ServletRequest and ServletResponse are used in the ServletRequest#startAsync(-).

Sign up to vote on this title
UsefulNot useful