This chapter is the first of our 2 practice Exams. It contains 60 Questions and you can take upto 90 minutes to answer all of them.
Remember that the exam contains the same number of Questions ‘60’ and you will be given the same 90 minutes only. So, make sure you time yourself and don't use more than the allotted time.
Regarding a typical HTTP request/response cycle, which of the following places the described events in their proper order? (Choose two.)
A. The Web browser makes an HTTP request, the Web server receives the request, and the Web server hands off the request to the servlet container.
B. A client responds to a servlet validation ping, Web server receives the request, and the Web server hands off the request to the servlet container.
C. The servlet container receives a request. The container reads the configuration (web.xml), and then calls the appropriate servlet.
D. The servlet polls the request object to find out what to do, the servlet performs its logic, and then sends data back to the client via the response object.
Which of the following are true about JSP comments? (Choose two.)
A. The JSP syntax is < % - - comment - - % >
B. The JSP syntax is < ! - - comment - - >
C. The XML syntax is < jsp: comment >< /jsp: comment >
D. They document the JSP page but is not inserted into the response.
Servlets are a required API of which Java 2 platform?
Which of following methods represents the servlet life cycle described in the API? (Choose three.)
Which two of the following are true regarding the container initializing a servlet before it can handle requests from clients? (choose two)
A. The container calls the init method.
B. The container calls the service method.
C. This is how you can keep track of request activities.
D. This is how you set up a catch/try block.
During initialization, the servlet instance can throw which exceptions? (Choose two.)
Which of the following statements regarding the forward method of the RequestDispatcher interface are true?
A. It must be called before the response buffer is full.
B. It can throw an IllegalStateException exception.
C. It requires an absolute path. A relative path won't work.
D. The client must have this feature turned on.
If during initialization, the servlet instance throws an exception, which of the following statements is true regarding the destroy() method?
A. The method is called finalize().
B. The container calls the destroy() method.
C. The container invokes the catch block.
D. The container doesn't call the destroy method after an exception.
Which exceptions can a servlet throw during the service of a request? (Choose two.)
Which two of the following are true about page directives in JSP?
A. They define attributes that apply to an entire JSP page.
B. If a variable is declared it must appear before it used in the JSP.
C. You can declare instance variables with them.
D. There can only be one.
Which two statements are true regarding how the servlet container will keep a servlet loaded? (choose two)
A. A servlet instance may be kept active in a servlet container for the lifetime of the servlet container.
B. When the session ends, the servlet is unloaded.
C. The specification defines a session to have a default timeout of 20 minutes.
D. There is no association between how long a servlet is loaded and the session.
Before the servlet container may destroy a servlet, what must be true?
A. Pending requests are flushed.
B. HttpSession calls finalize().
C. ServletContext calls finalize().
D. Threads that are currently running in the service method of the servlet must complete execution.
Regarding container paths and URL, which of the following equations is always true?
A. requestURI = contextPath + servletPath + pathInfo
B. requestURI = contextPath + pathInfo + servletPath
C. contextPath = requestURI + servletPath + pathInfo
D. servletPath = contextPath + pathInfo
How do you include an outside resource into a JSP page?
A. < jsp: include page="salesTax.jsp" >
< /jsp: include >
B. < jsp: include uri="salesTax.jsp"/ >
C. < jsp: include page="salesTax.jsp" >
< jsp: param name="state" value="CA" / >
< jsp: param name="amount" value="359.92" / >
< /jsp: include >
D. < jsp: include uri="salesTax.jsp" >
< jsp: param name="state" value="CA" / >
< /jsp: include >.
What information does the client send back as part of a cookie?
A. date, location, name, and value
B. name and value
C. location, name, and value
D. server version, date, and SSL status
What is the lifetime of the request object?
A. Until all threads associated with the session are complete.
B. This is container vendor specific.
C. Like garbage collection, exact timing is not specified.
D. It depends on the scope of a servlet's service method.
Which of the following are true about includes in JSP? (Choose two.)
A. There is no such thing.
B. The XML syntax is < jsp: text > < /jsp: text >
C. The JSP syntax is < %@ include file="relativeURL" % >
D. The JSP syntax is < % include("string") % >
E. The included text is added to the JSP page at translation time, when the JSP page is compiled.
What does a servlet container do with buffering? (Choose two.)
A. It is allowed to buffer output going to the client.
B. It is not required to buffer output going to the client.
C. It is required to buffer output going to the client.
D. The container can be configured to buffer in the buffer.xml configuration file.
Which of the following are true about the declarations in JSP? (Choose two.)
A. The JSP syntax is < %@ declaration % >
B. The JSP syntax is: < %! declaration % >
C. The XML syntax is < jsp: declare >< /jsp: declare >
D. The JSP syntax is < % declaration % >.
How do you write a message to the WebApp log?
Headers may contain data that represents which data types? (Choose two.)
Using the sendError method has what side effect? (Choose two.)
A. There is no way to catch errors after calling sendError.
B. It automatically calls the destroy method.
C. It commits the response.
D. It terminates the response.
Which two of the following methods terminate the response so that afterward no more output may be added to the response buffer? (choose two)
A. The sendError method.
B. The sendRedirect method.
C. The sendTerminate method.
D. The sendComplete.
Which two of the following are true regarding the Hypertext Transfer Protocol (HTTP)? (choose two)
A. It is a stateful protocol.
B. It is a stateless protocol.
C. Servlets use sockets to make it stateful.
D. Servlets can only handle real connections so it is the container vendor's responsibility to manage this.
Which of the follow are features of URL rewriting?
A. It converts relative to absolute paths.
B. It redirects clients to another URL.
C. It is used for sessions.
D. It appends to a query string.
When is a session considered established?
A. When a client joins it.
B. When you create a cookie on the client.
C. When the client is notified about the session.
D. When the request object is created.
Which of the following methods may be used to send error information back to a client? (Choose two.)
What is the correct syntax for assigning a value to a bean's property?
A. < jsp: property name="houseLotBean" property="id" value="33245" / >
B. < jsp: useBean name="houseLotBean" property="id" value="33245" / >
C. < jsp: setProperty name="houseLotBean" property="id" value="33245" / >
D. < jsp: setProperty property="id" value="33245" / >
Any object bound into a session is available to which other servlets?
A. Those servlets that share the same response.
B. Those servlets that have access to HttpSession.
C. Those servlets in the same container.
D. Those servlets that belong to the same ServletContext.
Some objects may require notification when they are placed into, or removed from, a session. This information can be obtained by having the object implement which interface?
When will the life of the session expire? (Choose two.)
A. When you call the expunge() method.
B. When you set the setMaxInactiveInterval to -1.
C. When you call the invalidate() method.
D. When the service method completes.
What are the methods of the RequestDispatcher interface? (Choose two.)
Using XML syntax, how do you add text to the JSP output stream?
A. < jsp: page text="your text here" / >
B. < jsp: text >
< /jsp: text >
C. < jsp: include param="text" value="your text here"/ >
D. < jsp: text value="text here"/ >
A servlet being used from within an include has access to which of the following? (Choose two.)
Which of the following statements is true about how a servlet binds an object attribute into an HttpSession implementation by name?
A. This is determined by the deployment descriptor.
B. It depends on how you extend a servlet.
C. It depends on the container.
D. It binds it to the HttpServletResponse object.
The HttpServlet abstract subclass has which of the following methods beyond the basic Servlet interface? (Choose two.)
Which of the following elements are legal in a JSP scriptlet? (Choose two.)
B. Variable declarations
C. jsp: useBean
D. XML action
Fill in the name of the method of HttpServletResponse used to notify the client of a servlet error (without parentheses and parameters).
Which of the following is true about template data in JSP?
A. The XML syntax is < jsp: template > < /jsp: template >
B. The XML syntax is < jsp: text > < /jsp: text >
C. The JSP syntax is < % expression % >
D. It is processed by the JSP engine.
Regarding changing the status in the response header, which statement is true?
A. You use the addStatus method.
B. You use the setStatus method.
C. You use the page directive.
D. You use an XML action directive.
Provide the name of the method that the servlet container calls on every request.
Regarding the taglib directive, which of the following two statements are true?
A. It names the tag library that defines the custom tags and specifies their tag prefix.
B. It is the tag-library directive, not the taglib directive.
C. It declares that the JSP page uses custom tags.
D. It declares that the JSP page can use beans as defined in the directive.
What happens when the session attribute of the page directive is false? (Choose two.)
A. The session attribute doesn't go in the page directive.
B. You cannot use the session object.
C. Referring to a session object in the code causes a translation-time error.
D. The session attribute can only be specified with XML, not JSP syntax.
How do you specify that a given JSP page can be used as an error page?
A. There is no tag for this. It must be done in the web.xml configuration file.
B. Set the isErrorPage attribute of the page directive to true.
C. Place it in the error directory.
D. Use the include element.
Regarding a JSP page that inherits a class, which two of the following are true?
A. Servlets can inherit a class so JSP pages can too.
B. It uses the extends="package.class" attribute of the page directive.
C. It can only inherit another JSP page, not a servlet.
D. It can only inherit a JSP page with the same superclass.
Which statement is true about JSP expressions?
A. You must convert them to strings to append them to the output stream.
B. The JSP syntax is < % expression % >
C. The JSP syntax is < %=expression % >
D. The JSP syntax is < % System.out.print(expression) % >
Regarding forwarding a request to a Web resource in JSP, what two of the following are true?
A. You use the page directive. Set the forward attribute to true.
B. You can't do this in JSP. Do it at the servlet level.
C. < jsp: forward page="< %= expression % >" / >
D. < jsp: forward page="relativeURL" >
< jsp: param name="parameterName"
value="parameterValue" / > +
< /jsp: forward >
Which of the following are true about the include directive and the jsp: include element?
A. The include directive is processed when the JSP page is translated into a servlet class. The jsp: include element is processed when a JSP page is executed.
B. The include directive is processed when the JSP page is compiled into a servlet class. The jsp: include element is processed when a JSP page is translated.
C. The include directive is processed when the JSP page is translated into a servlet class. The jsp: include element is processed when a JSP page is translated.
D. The include directive is processed when the JSP page is executed into a servlet class. The jsp: include element is processed when a JSP page is executed.
How can a servlet set headers of an HTTP response? (Choose two.)
A. Using a query string.
B. Using POST.
C. Using addHeader.
D. Using setHeader.
What kind of scheme is the HTTP protocol?
If you wanted to use a conditional piece of code, which of the following shows where would you place it?
A. < jsp: scriptlet > code goes here < /jsp: scriptlet >
B. < jsp: code > code goes here < /jsp: code >
C. < jsp: include > code goes here < /jsp: include >
D. < jsp: jsp > code goes here < /jsp: jsp >
How would you forward a request to another resource?
A. < jsp: forward url="page.htm" / >
B. < jsp: forward param="page.htm"/ >
C. < jsp: forward uri="page.htm" / >
D. < jsp: forward page="page.htm" / >
What does the sendError method do?
A. It sends an error message to the server.
B. It sends an error message to the client log.
C. It logs an error.
D. It sends an error response to the client using the specified status.
Requests are represented by which two of the following objects? (choose two)
B. Servlet Request
Regarding passing an exception object to the method that writes information to the log file, which statement is true?
A. You can pass a string but not an exception object to the method that logs a message.
B. You can pass an exception object to the ServletContext.errorLog method that logs a message.
C. The exception must be converted to a string first.
D. You can use the response.log method to write to the log.
Which of the following will include the text of a resource at translation time?
A. < %@ include file="relativeURLspec" % >
B. < %! include file="relativeURLspec" % >
C. < %jsp: include file="relativeURLspec" % >
D. < %@ page import="relativeURLspec" % >
Which two of the following are correct uses of the RequestDispatcher (assume req is a correctly instantiated object of HttpServletRequest)? (choose two)
A. req.getRequestDispatcher(forwardURL). forward(req, res);
B. req.getRequestDispatcher(includeURL). include(req, res);
C. req.getRequestDispatcher.include(req, res);
D. req.getRequestDispatcher.forward(req, res);
What happens if you send data to the client after sendError has been called?
A. The information is ignored by the server.
B. The information is ignored by the client.
C. The method will throw IllegalStateException.
D. The method will throw IllegalSendException.
Which design pattern acts as a proxy and reduces network traffic?
A. Value objects
C. Data access objects
D. Business delegate
Regarding the sendRedirect method, which two of the following statements are true? (Choose two.)
A. It is legal to call the sendRedirect method with a relative URL path.
B. It is legal to call the sendRedirect method with an absolute URL path.
C. You must redirect to a servlet that implements the same interface.
D. You must redirect to a resource that must be defined in the deployment descriptor.
Previous Chapter: Chapter 59 - Exam Preparation Tips
© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.