PRJ321

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the result of attempting to access the following JSP page? (Choose one.) <html> <body> <%!public String method(){ Return"JAD Final Test"; } %> <h2><%=method()%></h2> </body> </html> "JAD final test" is output to the resulting web page.

"JAD final test" is output to the resulting web page.

Which of the following direcrories are legal locations for the deployment descriptor file? Note that all paths are shown as from the root of the machine or driver.(Choose one.) /appserverIntallDirectory/webapps/webappName/WEB-INF/xml

/appserverIntallDirectory/webapps/webappName/WEB-INF/xml

Which of the following are potentially legal lines of JSP cource?(Choose two.) <% String myValue = "myValue";%> <isp:setProperty name="beanName1" property="soleProp" value="<%=myValue%>"/> <jsp:useBean id="beanName1" class="a.b.myBean" type="a.b.Myinterface"/>

<% String myValue = "myValue";%> <isp:setProperty name="beanName1" property="soleProp" value="<%=myValue%>"/> <jsp:useBean id="beanName1" class="a.b.myBean" type="a.b.Myinterface"/>

Which of these is a correct fragment within the web-app element of deployment descriptor? Select the two correct answers. <error-page><error-code>404</error-code><location>?error.jsp</location></error-page> <error-page><exception-type>mypackage.MyException</exceptiontype><location>/error.jsp</location></error-page>

<error-page><exception-type>mypackage.MyException</exceptiontype><location>/error.jsp</location></error-page> <error-page><error-code>404</error-code><location>?error.jsp</location></error-page>

Which of the following correctly represents the following JSP statement. Select the one correct answer <jsp: expression>x</jsp: expression>

<jsp: expression>x</jsp: expression>

Which of the following represents the XML equivalent of this statement <%@ include file="a.jsp"%>. Select the one correct statement. <jsp:directive.include file="a.jsp"/>

<jsp:directive.include file="a.jsp"/>

A bean with a property color is loader using the following statement <jsp:usebean id="fruit" class="Fruit"/> Which of the following statements may be user to print the value of color property of the bean? Select the one correct answer. <jsp:getProperty name="fruit" property="color"/>

<jsp:getProperty name="fruit" property="color"/>

Which of these is a correct example of specifying a listener element resented by MyClass class? Assume myServlet element is defined correctly. Select the one correct answer. <listener><listerner-class>MyClass</listener-class></listener>

<listener><listerner-class>MyClass</listener-class></listener>

5. What is the likely effect of calling a servlet with the HEAD HTTP method if that servlet does not have a doHead() method? (Choose one.) A.200 response code: SC_OK B. 404 response code: SC_NOT_FOUND C. 405 response code: SC_METHOD_NOT_ALLOWED D. 500 response code: SC_INTERNAL_SERVER_ERROR E. 501 response code: SC_NOT_IMPLEMENTED

A

6. See the extract from web.xml below: <servlet-mapping> <servlet-name>ServletA</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>ServletB</servlet-name> <url-pattern>/bservlet.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>ServletC</servlet-name> <url-pattern>*.servletC</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>ServletD</servlet-name> <url-pattern>/dservlet/*</url-pattern> </servlet-mapping> Given that a user enters the following into her browser, which (if any) of the mapped servlets will execute? (Choose one.)14 http://myserver:8080/mywebapp/Bservlet.html A. ServletA B. ServletB C. ServletC D. ServletD E. The answer is dependent on the web container you use. F. None of the above: A 404 "page not found error" will result.

A

Given a servlet containing the following code, what is the outcome of attempting to compile and run the servlet? (Choose one.) ServletContext context = getServletContext();21 String s = context.getAttribute("javax.servlet.context.tempdir"); A. The servlet won't compile. B. The servlet won't run. C. String s has a null value. D.String s has a valid directory as its value. Attributes, Scope, and Multithreading

A

Identify true statements about fi lters. (Choose one.) A. You cannot work directly with the request object that is passed as a parameter to the filter. B.The order of fi lter processing is arbitrarily determined by the web container. C. Only URL patterns can be used by fi lters to target specifi c web resources. D. You must implement the doChain(request, response) method to pass control from fi lter to fi lter, or fi lter to servlet

A

ServletA forwards to ServletB, which includes Servlet C, which forwards to ServletD, which includes ServletE. When ServletA is requested, which servlets might contribute to the fi nal response? (Choose one.)26 A. ServletD and ServletE B. ServletB, ServletC, ServletD, and ServletE C.ServletD only E. ServletB only F. All of them

A

What is the outcome of attempting to compile, deploy, and run the following servlet code? Line numbers are for reference only and should not be considered part of the code. (Choose one.) 10 import java.io.*; 11 import javax.servlet.*; 12 import javax.servlet.http.*; 13 public class Question2 extends HttpServlet { 14 protected void doGet(ServletRequest request, 15 ServletResponse response) throws ServletException, IOException { 16 HttpSession session = request.getSession(false); 17 session.invalidate();29 18 session.setAttribute("illegal", "exception thrown""); 19 } 20 } A. Won't compile B. NullPointerException at line 16 on client's fi rst call to servlet C. IllegalStateException at line 18 D. Some other runtime exception E. None of the above

A

Which of the following is a legal fi lter mapping declaration in the deployment descriptor? (Choose one.) A. <filter-mapping> <filter-name>MicroPaymentFilter</filter-name> <servlet-name>MicroPaymentServlet</servlet-name> <dispatcher>REQUEST</dispatcher> </filter-mapping> B. <filter> <filter-name>MicroPaymentFilter</filter-name> <filter-class>webcert.ch03.MicroPaymentFilter</filter-class> <filter-mapping> <url-pattern>/MicroPaymentServlet</url-pattern> </filter-mapping> </filter> C. <filter-mapping> <filter-name>MicroPaymentFilter</filter-name> <url-pattern>MicroPayment/*</url-pattern>27 </filter-mapping> D. <filter> <filter-name>MicroPaymentFilter</filter-name> <filter-class>webcert.ch03.MicroPaymentFilter</filter-class> <filter-mapping> <servlet-name>MicroPaymentServlet</servlet-name> </filter-mapping> </filter>

A

Identify correct statements about WAR files from the list below. (Choose three.)19 A. A META-INF directory will be present in the WAR file. B.A WEB-INF directory will be present in the WAR file. C. A web container can't work directly from a WAR file; it must be extracted (unzipped) into the file system. D. A WAR file is in ZIP file format.

A B D

3. Which of the following are valid servlet methods that match up with HTTP methods? (Choose four.)4 A. doGet() B. doPost() C. doConnect() D. doOptions() E. doHead() F. doRequest() G. doService()

A B D E

1. Which of the following directories are legal locations for the deployment descriptor file? Note that all paths are shown as from the root of the machine or drive. (Choose two.) A. / WEB-INF B. /appserverInstallDirectory/webapps/webappName/ WEB-INF/xml C. /appserverInstallDirectory/webapps/webappName/ WEB-INF D. /appserverInstallDirectory/webapps/webappName/ WEB-INF/cl

A C

Which of the following mechanisms will guarantee that every session in a web application will expire after 1 minute? You can assume that for each answer below, this is the only session timeout mechanism in force for the web application. (Choose two.) A. In the deployment descriptor: <session-config>30 <session-timeout>1</session-timeout> </session-config> B. In the deployment descriptor: <session-config> <session-timeout>60</session-timeout> </session-config> C. In the doFilter() method of a fi lter that has the following <url-pattern> mapping in the deployment descriptor: "/." request is an instance of HttpServletRequest, cast from the ServletRequest parameter passed to the method. HttpSession session = request.getSession(); session.setMaxInactiveInterval(60); D. In the doGet() method of a servlet. request is an instance of HttpServletRequest, passed as a parameter to the method. HttpSession session = request.getSession(); session.setMaxInactiveInterval(1); E. In the init() method of a servlet that loads on start up of the web application. request is an instance of HttpServletRequest, passed as a parameter to the method. HttpSession session = request.getSession(); session.setMaxInactiveInterval(60); Session Management

A C

11. Which of the following are likely to found as request header fi elds? (Choose three.) A. Accept B. WWW-Authenticate C. Accept-Language D. From E. Client-Agent F. Retry-After

A C D

Identify correct statements about the META-INF directory from the list below. (Choose three.) A. META-INF is a suitable location for storing digital certifi cates. B. META-INF is used as a repository for common code. C. The MANIFEST.MF file is found in the META-INF directory. D. The deployment descriptor fi le is found in the META-INF directory. E. META-INF is not directly accessible to clients

A C E

Under which of the following circumstances are servlets most likely to be instantiated? (Choose four.) A. During web application startup B. If there are insuffi cient instances of the servlet to service incoming requests C. On a client first requesting the servlet D. At the same time as a different servlet is instantiated, when that different servlet makes use of the servlet in question E. After the servlet's destroy() method is called, dependent on the server's keep-alive setting F. At some arbitrary point in the web application or application server lifetime G. After the time specified on an UnavailableException has expired

A C F G

What are possible outcomes from executing the doGet method in ServletC below? (Choose two.) public class ServletC extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { RequestDispatcher rd = getServletContext().getRequestDispatcher( "ServletB"); rd.forward(req, resp); } } A. HTTP 500 error (error in 500s). B. NullPointerException. C. HTTP 404 error. D. Some other exception. E. ServletNotFoundException. F. ServletB runs. G. A fi le called ServletB is served from the context directory

A D

Which of the HTTP methods below are likely to change state on the web server? (Choose three.) A. DELETE B. TRACE C. OPTIONS D. POST E. PUT F. CONNECT G. HEAD H. SERVICE

A D E

23. Which of the following are true statements about servlet availability? (Choose two.) A. If a servlet is removed from service, then any requests to the servlet should result in an HTTP 404 (SC_NOT_FOUND) error. B. The init() method must not throw an UnavailableException. C.If permanent unavailability is indicated via an UnavailableException, a servlet's destroy() method must be called. D. Servlet containers must distinguish between periods of temporary and permanent unavailability E. If a servlet is deemed temporarily unavailable; a container may return an HTTP 503 (SC_SERVICE_UNAVAILABLE) message on receiving requests to the servlet during its time of unavailability.

A E

Which of the following methods can be used to add cookies to a servlet response? (Choose two.) A. HttpServletResponse.addCookie(Cookie cookie) B. ServletResponse.addCookie(Cookie cookie) C. HttpServletResponse.addCookie(String contents) D. ServletResponse.addCookie(String contents) E. HttpServletResponse.addHeader(String name, String value) F. ServletResponse.addHeader(String name, String value)

A E

Identify the two equivalent method calls in the list below. (Choose two.) A. HttpServletRequest.getSession() B.ServletRequest.getSession() C. ServletRequest.getSession(true) D. HttpServletRequest.getSession(false) E. ServletRequest.getSession(false) F. HttpServletRequest.getSession(true) G. HttpServletRequest.getSession("true") H. ServletRequest.getSession("false")

A F

Which of the approaches below will correctly cause a client to redirect to an alternative URL? (In the code fragments below, consider that "response" is an instance of HttpServletResponse.) (Choose two.) A. response.sendRedirect("index.jsp"); B. response.setLocation("index.jsp"); C. RequestDispatcher rd = response.getRequestDispatcher("index.jsp"); rd.sendRedirect(); D. response.redirect("index.jsp"); E. response.setHeader("Location", "index.jsp"); F. response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT); response.setHeader("Location", "index.jsp")

A F

When a web server responds to a request from a browser or other Web client the response typically consists of. (choose one) A status line, some response headers, a blank line, and the document.

A status line, some response headers, a blank line, and the document.

Which of the following statements are correct about the status of the Http response? Select the one correct answer A status of 200 to 299 signifies that the request was successful

A status of 200 to 299 signifies that the request was successful

A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> What happen when the following statement is executes. Select the one correct answer. <jsp:setPropety name="fruit" property=""/> All the properties of the fruit bean are assignet the values of input parameters of the JSP page that have the same name

All the properties of the fruit bean are assignet the values of input parameters of the JSP page that have the same name

7. What is the parent tag for <welcome-file-list>? (Choose one.) A. <welcome-file> B. <web-app> C. None — the tag doesn't exist. D. <welcome-files> E. <servlet>

B

Given fi ve servlets with <load-on-startup> value set as follows, and declared in the following order in the deployment descriptor, ¦ ServletA: 1 ¦ ServletB: 0 ¦ ServletC: 1 ¦ ServletD: 1 ¦ ServletE: no value set for <load-on-startup> Identify true statements from the list below. (Choose one.) A. ServletA will load before ServletB. B. ServletB will load before ServletC. C. ServletC will load before ServletD. D. ServletD will load before ServletE. E. ServletA will load before ServletE.

B

What is the likely result from attempting to compile and execute the following servlet code? (Choose one.) HttpSession session = getSession(); String s = session.getAttribute("javax.servlet.session.tempdir"); A. Won't compile for one reason. B. Won't compile for more than one reason. C. Runtime exception when attempting to get access to the attribute. D. s contains null. E. s contains a valid String, denoting a temporary directory.

B

What is the outcome of executing ServletA? You can assume that (1) ServletB has a mapping of"/ServletB" and a name of "ServletB," and (2) imports have been omitted from the code for breity; the code will compile successfully. (Choose one.)23 public class ServletA extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { RequestDispatcher rd = getServletContext().getNamedDispatcher( "ServletB"); rd.forward(req, resp); } } public class ServletB { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String attr = (String) req.getAttribute("javax.servlet.forward.servlet_path"); PrintWriter out = resp.getWriter(); out.write("Attribute value: " + attr); } } A. NullPointerException thrown B. "Attribute value: null" output to the web page C. A blank web page D. ServletNotFoundException thrown E. "Attribute value: /ServletB" output to the web page F. "Attribute value: ServletB" output to the web page G. ClassCastException thrown

B

What is the web page output from executing ServletD with the URL below? (Choose one.) http://localhost:8080/myapp/ServletD?fruit=orange public class ServletD extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { RequestDispatcher rd = getServletContext().getRequestDispatcher( "/ServletE?fruit=pear"); rd.forward(req, resp); } } public class ServletE extends HttpServlet {25 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); PrintWriter out = response.getWriter(); String[] valueArray = request.getParameterValues("fruit"); for (int i = 0; i < valueArray.length; i++) { if (i > 0) { out.write(", "); } out.write(valueArray[i]); } String queryString = (String) request.getAttribute("javax.servlet.forward.query_string"); int pos = queryString.indexOf("=") + 1; String values = queryString.substring(pos); out.write(", " + values); } } A. pear, pear B. pear, orange, orange C. orange, pear, orange D. orange, pear, pear E. orange, pear F. pear, orange, null G. orange, pear, null H. pear, orange, pear, orange

B

What request header must be set for parameter data to be decoded from a form? (Choose one.) A. EncType: application /x-www-urlencoded B. Content-Type: application /x-www-form-urlencoded C. Content-Type: multipart /form-data D. Encoding-Type: multipart /form-data E. Accept-Encoding: application/www-form-encoded F. Encoding-Type: multipart/www-form-data

B

What will be the outcome of compiling and deploying the servlet code below? (You can assume that correct import statements are provided and that the servlet lives in the default package. Line numbers are for ease of reference and are not part of the code.) 11 public class NameServlet extends HttpServlet { 12 protected void doGet(HttpServletRequest request, 13 HttpServletResponse response) { 14 out.write(getServletName());16 15 } 16 } A. Will not compile because the doGet() method doesn't throw the correct exceptions B. Will not compile for some other reason C. When run, terminates with a ServletNotFoundException at line 14 D. Outputs "NameServlet" E. Outputs the contents of the corresponding <servlet> element F. Outputs the contents of the corresponding <servlet-name> element

B

Which of the following servlet methods can return null? (Choose one.) A. getInitParameterNames() B. getInitParameter(String name) C. getServletName() D. getServletContext()

B

Identify true statements about scope from the following list. (Choose two.) A. Context scope can span JVMs. B. Session scope can span JVMs. C. Requests can span web apps. D. Sessions can span web apps. E. Requests can span JVMs

B C

Identify true statements from the list below. (Choose two.) A. Attribute methods don't throw exceptions. B. You cannot remove request parameters. C. Attributes can be set by the web container or by application code. D. Attribute values are String objects. E. "malhereusement" is an illegal name for an attribute.

B C

5. Identify which of the following are true statements about web applications. (Choose three.) A. The only way to access resources under the / WEB-INF directory is through appropriate servlet mapping directives in the deployment descriptor. B. Server-side code has access to all resources in the web application. C. Clients of web applications can't directly access resources in / WEB-INF/tld. D. A good place to keep a .tld (tag library fi le) is directly in the / WEB-INF directory.

B C D

24. Under what circumstances will a servlet instance's destroy() method never be called? (Choose two.) A. As a result of a web application closedown request B. When init() has not run to completion successfully12 C. If no thread has ever executed the service() method D. After destroy() has already been called E. During servlet replacement

B D

Identify true statements about sessions from the list below. (Choose two.) A. Sessions can span web applications. B. Sessions can be cloned across JVMs. C. Sessions are destroyed only after a predefi ned period of inactivity. D. Sessions can be set to never time out. E. You can use the deployment descriptor to cause sessions to expire after a set number of requests.

B D

What is the outcome of running the following servlet code? (Choose two.) public void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain;charset-UTF-8"); PrintWriter out = response.getWriter(); out.flush(); out.close(); System.out.println(response.isCommitted()); response.setContentType("illegal/value"); } A An IllegalArgumentException is thrown. B. A blank page is returned to the client. C. A 500 error is reported to the client. D. "true" is output on the server's console. E. "false" is output on the server's console

B D

Identify correct statements about session management from the list below. (Choose two.) A. Session management is usually dependent on a hidden form fi eld called JSessionId. B. The unique identifi er for a session may be passed back and forward through a name/value pair in the URL. The name is jsessionid.31 C. If a cookie used for default session management, there is some fl exibility with the name used for the cookie. D. The cookie used for default session management must be added to the response using the HttpServletResponse.addCookie(Cookie theCookie) method. E. The rules for rewriting URLs for links may be different from those for rewriting URLs for redirection.

B E

What results from a call to the getInitParameterNames() method on ServletContext when there are no context parameters set up in the deployment descriptor? (Choose two.) A. A NoParametersExistException is thrown. B. An empty Enumeration object is returned. C. null is returned. D. An ArrayList object of size zero is returned. E. No exceptions are thrown. F. An empty Iterator object is returned.

B E

Which of the following are true statements about the deployment descriptor for a web application? (Choose two.) A. At least one <servlet> element must be present. B. <welcome-file> is a child element of <welcome-file-list>. C. <web-application> is the root element. D. <servlet> elements must all be declared before <servlet-mapping> elements. E. At least one element must be present.

B E

In ejb-jar.xml file. <persistence-type> element value is ________________ Bean or Container

Bean or Container

The _________________ supplies business components, of enterprise beans Bean provider

Bean provider

Study the statements: 1) The special directory/WEB-INF/lib contains Java class files-servlets and supporting code. 2) The special directory/WEB-INF/class contains JAR files with supporting libraries of code. Both 1 and 2 a not true

Both 1 and 2 a not true

23. Study the statements: 1) URL rewriting may be used when a browser is disabled. 2) In URL encoding the session id is included as part of the URL. Both 1 and 2 are true

Both 1 and 2 are true

4. What is the likely effect of calling a servlet with the POST HTTP method if that servlet does not have a doPost() method? (Choose one.) A. If the servlet has a doGet() method, it executes that instead. B.404 response code: SC_NOT_FOUND. C. 405 response code: SC_METHOD_NOT_ALLOWED. D. 500 response code: SC_INTERNAL_SERVER_ERROR. E. 501 response code: SC_NOT_IMPLEMENTED

C

From the available options, what is the likely outcome from running the code below? (Choose one.) protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = getServletContext().getNamedDispatcher("/ServletB"); dispatcher.forward(request, response); } A. DispatcherNotFoundException. B. Runtime error because of incorrectly formed parameter to getNamedDispatcher() method. C. NullPointerException. D. ServletB can obtain request attribute javax.servlet.forward.request_uri

C

From the following list, what is a probable outcome from a call to the ServletContext.getAttributeNames() method? (Choose one.) A. A null reference is returned. B. An empty Enumeration is returned. C. A nonempty Enumeration is returned. D. An empty ArrayList is returned. E. A nonempty ArrayList is returned. F. A NoAttributesFoundException is thrown. G. Some other exception is thrown.

C

Identify the default mechanism for session management from the list below. (Choose one.) A. URL rewriting B. Hidden Form Fields C. Cookies D. SSL E. jsessionId request parameter

C

Under what circumstances can the HttpServletRequest.getHeaders(String name) method return null? (Choose one.) A. If there are no request headers present in the request for the given header name. B. If there are multiple headers for the given header name.9 C If the container disallows access to the header information. D. If there are multiple values for the given header name. E. If there is only a single value for the given header name. F. There is no such method on HttpServletRequest.

C

What of the following represents a correct declaration of a servlet in the deployment descriptor? (Choose one.) A. <servlet> <servlet-class>MyServlet</servlet-class> <servlet-name>MyServlet</servlet-name> </servlet> B.<servlet> <servlet-name>MyServlet</servlet-name> <servlet-class>MyServlet.class</servlet-class>15 </servlet> C. <servlet> <description>MyServlet</description> <servlet-name>MyServlet</servlet-name> <servlet-class>MyServlet</servlet-class> </servlet> D. <servlet> <servlet-class>MyServlet</servlet-class> <jsp-file>index.jsp</jsp-file> </servlet>

C

Which of the HTTP methods below is not considered to be "idempotent"? (Choose one.) A. GET B. TRACE C. POST D. HEAD74 E.OPTIONS F. SERVIC

C

Identify statements that are always true about threads running through the service()11 method of a servlet with the following class declaration. (Choose two.) public class MyServlet extends HttpServlet { // servlet code } A.The destroy() method never cuts short threads running through the service() method. B. Threads running through the service() method must run one at a time. C. There could be anything from zero to many threads running through the service() method during the time the servlet is loaded. D. If the init() method for the servlet hasn't run, no threads have yet been able to run through the service() method. E. At least one thread will run through the service() method if init() has been executed

C D

Identify which of the following are names of special attributes associated with the dispatching mechanism. (Choose two.) A. java.servlet.include.servlet_name B. javax.http.servlet.include.query_name C. javax.servlet.include.servlet_path D. javax.servlet.forward.request_url24 E. javax.servlet.include.path_info F. java.servlet.forward.context_path

C E

6. What will be the result of pressing the submit button in the following HTML form? (Choose two.) <form action="/servlet/Register"> <input type="text" name="fullName" value="Type name here" /> <input type="submit" name="sbmButton" value="OK" /> </form> A. A request is sent with the HTTP method HEAD. B. A request is sent with the HTTP method POST. C. A request is sent with the HTTP method GET.5 D. The parameter fullName is the only parameter passed to the web server in the request URL. E. The parameter fullName is the only parameter passed to the web server as part of the request body. F. The parameters fullName and sbmButton are passed to the web server in the request URL. G. The parameters fullName and sbmButton are passed to the web server as part of the request body. H. No parameters are passed to the web server

C F

A ______________has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. Cookie

Cookie

Given the following deployment descriptor: <web-app>17 <servlet> <servlet-name>InitParams</servlet-name> <servlet-class>com.osborne.c02.InitParamsServlet</servlet-class> <init-param> <param-name>initParm</param-name> <param-value>question14</param-value> </init-param> </servlet> </web-app> What is the outcome of running the following servlet? (Choose one.) public class InitParamsServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext sc = this.getServletContext(); PrintWriter out = response.getWriter(); out.write("Initialization Parameter is: " + sc.getInitParameter("initParm")); } } A. A runtime error B. "Initialization Parameter is: null" written to the console C. "Initialization Parameter is: question14" returned to the requester D. "Initialization Parameter is: null" returned to the requester E. "Initialization Parameter is: question14" written to the console

D

What is the likely outcome of attempting to compile and run the following servlet code, assuming there is one cookie attached to the incoming request? 11 Cookie[] cookies = request.getCookies(); 12 Cookie cookie1 = cookies[0]; 13 response.setContentType("text/plain"); 14 String attributes = cookie1.getName(); 15 attributes += cookie1.getValue(); 16 attributes += cookie1.getDomain(); 17 attributes += cookie1.getPath(); 18 response.getWriter().write(attributes); A. Compilation error at line 11 B. Compilation error at line 16 C. Output to the response including at least the name and domain D. Output to the response including at least the name and value E. Output to the response including at least the name, value, and domain F. Output to the response including all of name, value, domain, and path

D

What is the likely outcome of attempting to run the following servlet code? String[] values = request.getHeaders("BogusHeader");8 response.setContentType("text/plain"); response.getWriter().write(values[0]); A. IllegalArgumentException B. NumberFormatException C. Won't run: 1 compilation error. D. Won't run: 2 compilation errors. E. Nothing written to the response. F. null written to the response.

D

What is the most likely outcome of running the following servlet code? (Choose one.) long date = request.getDateHeader("Host"); response.setContentType("text/plain"); response.getWriter().write("" + date); A. A formatted date is written to the response. B. 1 is written to the response. C. Won't run because won't compile. D. IllegalArgumentException E. NumberFormatException F. DateFormatException

D

What's the likely outcome of a user entering the following URL in her browser? You can assume that index.html does exist in /WEB-INF/html, where /WEB-INF/html is a directory off the context root, and that the server, port, and context details are specified correctly. (Choose one.)13 http://localhost:8080/mywebapp/WEB-INF/html/index.html A. Because the fi le is an HTML fi le, the web application serves it back to the browser. B. An HTTP response code in the 500 range is returned (server error). C. An HTTP response code of 403 is returned to indicate that the server is not allowed to serve fi les from this location. D. An HTTP response code of 404 returned to indicate that the requested resource has not been found. E. None of the above.

D

Which of the following is a valid way to set up a mime mapping in the deployment descriptor? (Choose one.) A. <mime-mapping-list> <mime-type>text/plain</mime-type> <extension>txt</extension> <mime-mapping-list> B. <mime-mapping-list> <extension>.txt</extension> <mime-type>text/plain</mime-type> <mime-mapping-list> C.<mime-mapping> <mime-type>txt</mime-type> <extension>text/plain</extension> <mime-mapping> D. <mime-mapping> <extension>txt</extension> <mime-type>text/plain</mime-type> <mime-mapping>

D

Given the following servlet code, identify the outputs that could not or should not occur during the lifetime of the web application housing the servlet. A. init:destroy: B. init:destroy:init:destroy: C. init:init:init: D. destroy:service: E. init:service:service:service:service:service: F. init:service:init:service:

D F

What is the result of loading the web-app with the following deployment descriptor and attempting to execute the following servlet? (Choose two.) <web-app> <context-param> <paramname>author</paramname> <paramvalue>Elmore Leonard</paramvalue> </context-param> </web-app> public class ContextInitParms extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter();20 out.write("<HTML><HEAD></HEAD><BODY>"); ServletContext sc = getServletContext(); out.write(sc.getInitParameter("auther")); out.close(); } } A. ParameterNotFoundException is thrown. B. Some other exception is thrown. C. "Elmore Leonard" is output on the web page. D. An application failure occurs. E. null is output on the web page. F. A 404 error occurs in the browser G. Some other error (status code in the 500s) occurs in the browser

D F

Consider the following form and servlet code. Assuming the user changes none of the default settings and presses submit, what will the servlet output in the response? (Choose one.) <form action="PrintParams?param1=First" method="post"> <input type="hidden" name="param1" value="First" /> <input type="text" name="param1" value="Second" /> <input type="radio" name="param1" value="Third" /> <input type="submit" /> </form> protected void doPost HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write("<html>\n<head>\n<title>Print Parameters</title>\n</head>\n<body>"); String[] param1 = request.getParameterValues("param1"); for (int i = 0; i < param1.length; i++) { out.write(param1[i] + ":"); } out.write("\n</body>\n</html>"); out.close(); }6 A. First:Second:Third B. First:Second:Second C. First:Third:Third D. Second:Third:First E. First:First:Second F. No response — servlet will not compile. G. No response — ServletException occurs.

E

Consider the following list of fi les in a web application, where myApp is the context path: /devDir/myapp/index.jsp /devDir/myapp/WEB-INF/web.xml /devDir/myapp/WEB-INF/classes/webcert/ch02/SomeServlet.class Which of the following sets of instructions will build a correctly formed web archive file? (Choose one.) A. None of the sets of instructions will build a valid WAR fi le until /webcert/ch02/SomeServlet.class is moved to the WEB-INF/ lib directory. B. Change directory to /devDir; execute jar tvf myapp.war *.* C. Change directory to /devDir/myApp; execute jar cvf myapp.jar *.* D.Change directory to /devDir/myApp/WEB-INF; execute jar xvf myapp.war *.* E. Change directory to /devDir/myApp; execute jar cvf someapp.war *.*

E

Given the following deployment descriptor, identify the sequence of fi lters that execute on a direct client request for ServletA. (Choose one.) <filter-mapping> <filter-name>LogFilter</filter-name> <servlet-name>ServletA</servlet-name> </filter-mapping>28 <filter-mapping> <filter-name>AuditFilter</filter-name> <url-pattern>/ServletA</url-pattern> <dispatcher>FORWARD</dispatcher> </filter-mapping> <filter-mapping> <filter-name>EncryptionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet-mapping> <servlet-name>ServletA</servlet-name> <url-pattern>/ServletA</url-pattern> </servlet-mapping> A. LogFilter, AuditFilter, EncryptionFilter B. LogFilter, EncryptionFilter C. LogFilter D. EncryptionFilter, AuditFilter, LogFilter E. EncryptionFilter, LogFilter F. AuditFilter, EncryptionFilter, LogFilter

E

Identify true statements about context parameters from the list below. (Choose one.) A. The deployment descriptor elements used to describe context parameter names and values are unique to the context parameter element. B. Context parameters must be declared in the deployment descriptor before servlets. C. Context parameters are available to all web applications loaded by an application server. D. In distributable applications, context parameters are duplicated between JVMs. E. None of the above.

E

What is result of attempting to run the following code? (Choose one.) public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("a", "request"); System.out.print(request.getAttribute("a")); request.setAttribute("a", "2nd request"); System.out.print(","); System.out.print(request.getAttribute("a")); request.removeAttribute("a");22 request.removeAttribute("a"); System.out.print(","); Object o = request.getAttribute("a"); System.out.print(o); } A. "request, request, 2nd request, null" written to standard output B. NullPointerException at line 22 C. AttributeAlreadyRemovedException at line 22 D. NullPointerException at line 24 E. "request, 2nd request, null" written to standard output F. "request, 2nd request" written to standard output G. "request, request, 2nd request" written to standard output

E

What will be the outcome of executing the following code? (Choose one.)10 public void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); response.setContentLength(4); PrintWriter out = response.getWriter(); out.write("What will be the response? "); out.write("" + response.isCommitted()); } A. Won't execute because of a compilation error. B. An IllegalArgumentException is thrown. C. An IllegalStateException is thrown. D. A blank page is returned to the client. E. "What" is returned to the client. F. "What will be the response?" is returned to the client. G. "What will be the response? true" is returned to the client. H. "What will be the response? false" is returned to the client.

E

Which of the following methods derive from the ServletConfig interface? (Choose three.) A. ServletContext getServletContext() B. String getInitParameter(String name) C. MapEntry getInitParameterEntry() D. Iterator getInitParameterNames() E. String getServletName()

E

Which of these are legal return types of the doAfterBody method defined in a class that extends TagSupport class. Select two correct answers. EVAL_BODY_AGAIN SKIP_BODY

EVAL_BODY_AGAIN SKIP_BODY

Which of these is legal return types of the doEndTag method defined in a class that extends TagSupport class? Select two correct answers. EVAL_PAGE SKIP_BODY

EVAL_PAGE SKIP_BODY

What would be the best directory in which to store a supporting JAR fi le for a web application? Note that in the list below, all directories begin from the context root. (Choose one.) A. / WEB-INF B. / WEB-INF/classes C. /jars D. /web-inf/jars E. /CLASSES F. / WEB-INF/lib G. /lib H. None of the above.

F

Assume that there is a fi le called secure.txt, located at / WEB-INF/securefi les, whose contents are "Password=WebCert." What statements are false about the result of compiling and running the following code? 11 public class CodeTestServlet extends HttpServlet { 12 protected void doGet(HttpServletRequest request, 13 HttpServletResponse response) throws IOException { 14 ServletContext sc = getServletContext(); 15 InputStream is = sc.getResourceAsStream("/WEB-" + 16 "INF/securefiles/secure.txt"); 17 BufferedReader br = new BufferedReader(new InputStreamReader(is)); 18 System.out.println(br.readLine()); 19 } 20 } A. The code will not compile. B. A RuntimeException will occur at lines 15/16. C. An IOException will occur at line 18. D. The string "Password=WebCert" will be returned to the requester. E. A, B, and C above. F. B, C, and D above. G. A, B, C, and D above.

G

9. What is the maximum number of parameter values that can be forwarded to the servlet from the following HTML form? (Choose one.) <html> <body> <h1>Chapter 1 Question 9</h1> <form action="ParamsServlet" method="get"> <select name="Languages" size="3" multiple> <option value="JAVA" selected>Java</option> <option value="CSHARP">C#</option> <option value="C" selected>C</option> <option value="CPLUSPLUS">C++</option> <option value="PASCAL">Pascal</option> <option value="ADA">Ada</option> </select> <input type="submit" name="button" /> </form> </body> </html> A. 0 B. 1 C. 2 D. 3 E. 47 F. 5 G. 6 H. 7

H

Name the class that includes the getSession method that is used to get the HttpSession object. HttpServletRequest

HttpServletRequest

Which of the following methods can be used to add cookies to a servlet reponse? HttpServletResponse.addCookie(Cookie cookie)

HttpServletResponse.addCookie(Cookie cookie)

A java bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> What is the effect of the following statement <jsp:sentproperty name="fruit" property="color"/> Select the one correct answer. If there is a non-null request parameter with name color then its value gets assigned to color property of Java Bean fruit

If there is a non-null request parameter with name color then its value gets assigned to color property of Java Bean fruit

The top three value of EJB are (choose 3) It is agreed upon by the industry. Portability is easier Rapid application development.

It is agreed upon by the industry. Portability is easier Rapid application development.

Which are EJB containers? (choose three) JBoss IBM WebSphere BEA's WebLogic

JBoss IBM WebSphere BEA's WebLogic

Message-driven beans are clsses that implement 02 interfaces:3 Javax.ejb.messageDrivenBean Javax.jms.MessagerListener

Javax.ejb.messageDrivenBean Javax.jms.MessagerListener

In EJB2.0, ejb-jar.xml deployment descriptor file must be placed in ______________folder. META-INF

META-INF

26. Study the statements about web.xml file: 1) The deployment descriptor file is called web.xml, and it must be located in the WEB_INF directory . 2) Web.xml is in XML (extended markup language) fomat. Its root element is <web>. Only statement 1 is true.

Only statement 1 is true.

Create() method of entity home interface returns ________ Remote object

Remote object

A ______________ session bean is a bean that holds conversations that span a single method call. Stateless

Stateless

Which of the following statements are true for <jsp:usebean>. Select the two correct answers. The id attribute must be defined for <jsp:usebean> The <jsp:usebean> must include either type or class attribute or both

The id attribute must be defined for <jsp:usebean> The <jsp:usebean> must include either type or class attribute or both

Select the word to replace ??? to make the diagram about messaging domain correct (ảnh) Topic

Topic

What is the output of the following JSP page. ${empty""}<br> S{empty"sometext"} True false

True false

Which ò 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 \doc-root\WEB-INF\web.xml

\doc-root\WEB-INF\web.xml

To send text output in a response. The following method of HttpServletResponse may be used to get the appropriate Writer/Stream object. Select the one correct answer. getOutputStream

getOutputStream

Name the implicit variable to JSP pages that may be used to access all the other implicit objects. pageContext

pageContext

ejbCreate() method of entuty bean class returns ________________ primary key

primary key


Ensembles d'études connexes

Greatest Common Factor and Least Common Multiple

View Set

film appreciation midterm - usd, mollman

View Set

Chapter 19: Endocrine Alterations

View Set

WQC 13/15 and Sports and Games from GTT

View Set

Pa real estate drill and practice qbank

View Set

Chapter 11 Project Risk Management

View Set