Mid1 Review1

SELECT THE BEST CHOICE (answer to the left of the question)(72%)

Code example 2-2

var $ = function ( id ) {

return document.getElementById( id );

}

var display_name_click = function () {

$("name_text_box").value = "Mike";

}

window.onload = function () {

$("display_button").onclick = display_name_click;

}

1. .(Refer to code example 2-2.) Assuming the web page for this script has a text field with an id attribute of name_text_box and a button with an id attribute of display_button, what will happen when the user clicks the button?

a. / The application will display “Mike” in a dialog box.
b. / The application will display “Mike” in the text field named name_text_box.
c. / The application will display “Mike” in the button named display_button.
d. / The application won’t display anything.

2. .(Refer to code example 2-2.) What does the code in the third function do?

a. / Assign an event handler named display_button to the click event of a button.
b. / Assign an event handler named display_name_click to the click event of a button.
c. / Create an event handler named display_button.
d. / Create a function named display_button.

3.The attributes of a <form> tag specify

a. / the name of the submit button and the submission method
b. / the name of the submit button and the URL for the server-side script
c. / the submission method and whether the data is passed as part of the URL
d. / the submission method and the URL for the server-side script

4.The controls of a form for a JavaScript application

a. / don’t have to include a submit button
b. / identify the form tag that they’re related to
c. / must include a reset button
d. / must include at least one text field

5.When you set the float property for a block element to left, the element will be floated

a. / to the left of other elements in the block
b. / to the right of other elements in the block
c. / to the left of any elements in the block that are wider
d. / to the right of any elements in the block that are wider

6.When you set the position property for a block element to absolute, the browser

a. / takes the element out of the flow of elements on the web page
b. / keeps the element in the flow of elements on the web page
c. / doesn’t allow the element to overlap other elements on the web page
d. / leaves space for the moved element on the web page as if it were still there

7.Given an event object that’s stored in a variable named evt, which of the following statements will cancel the default action in Internet Explorer?

a. / evt.returnValue = false; / c. / evt.cancelDefault()
b. / evt.preventDefault(); / d. / evt.cancelDefault = true;

8.What does the code that follows do?

var image = new Image();

image.src = "logo.jpg";

a. / Displays “logo.jpg” as a new image in the browser
b. / Replaces the image displayed by the image node with “logo.jpg”
c. / Preloads “logo.jpg”
d. / Clears “logo.jpg” from the browser’s cache

9All but one of the following is true for a WAR (Web Archive) file. Which one is it?

a. / A WAR file is a JAR file.
b. / A WAR file contains all the directories and files for a web application.
c. / When you deploy an application with a WAR file, the web server must be running.
d. / To deploy an application with a WAR file, you copy it into its document root directory.

10.The servlets for a web application are stored in this directory and its subdirectories:

a. / WEB-INF / c. / WEB-INF\lib
b. / WEB-INF\classes / d. / WEB-INF\servlets

11.The web.xml file can do all but one of the following. Which one is it?

a. / Define initialization parameters for a servlet.
b. / Define initialization parameters for the entire application.
c. / Enable servlet mapping so a client can call a servlet using any URL pattern.
d. / Set the web server port for the application.

12.If you have to change the port that’s used by Tomcat, you make the change in the

a. / server.xml file / c. / catalina.bat file
b. / web.xml file / d. / startup.bat file

13.If servlet reloading is turned on when a servlet is requested, Tomcat

a. / reloads the servlet before running it
b. / reloads the servlet if it is a later version than the one in memory
c. / reloads all of the servlets for the application
d. / reloads all the servlets for all of the deployed applications

14To use your own Java class in a JSP, you can import the class with a

a. / JSP scriptlet / c. / JSP directive
b. / JSP expression / d. / JSP declaration

15.In the code that follows, the numOfErrors variable

<%! int numOfErrors = 1; %>

a. / is initialized each time the page is requested
b. / is an instance variable that is not thread-safe
c. / is ignored by the JSP engine
d. / is invalid JSP code

16.When a JSP is requested for the first time, the JSP engine does all but one of the following. Which one is it?

a. / generates a servlet for the JSP
b. / generates the HTML code for the JSP
c. / creates one instance of the servlet class
d. / creates one thread

17.When a JSP is requested for the second time, the JSP engine

a. / creates a thread that has its own copy of the instance variables
b. / creates a thread that has its own copy of the local variables
c. / creates an instance of the JSP that has its own copy of the instance variables
d. / creates an instance of the JSP that has its own copy of the local variables

18 .A servlet is a Java class that extends the

a. / Servlet class / c. / HttpServlet class
b. / HttpGenericServlet class / d. / HttpServletRequest class

19.When the doGet method of a servlet is called, it receives

a. / the request and ServletContext objects
b. / the request and response objects
c. / the request, response, and ServletException objects
d. / the request, ServletContext, and ServletException objects

20.In the code that follows, DiagnoseTrouble

<servlet-mapping>

<servlet-name>DiagnoseTrouble</servlet-name>

<url-pattern>/diagnostics/diagnoseTrouble</url-pattern>

</servlet-mapping>

a. / is the name of the servlet class
b. / is the internal name for the class that’s used in the deployment descriptor
c. / is the name that’s used to request the servlet

21.In the code that follows, the servlet is mapped to

<servlet-mapping>

<servlet-name>DiagnoseTrouble</servlet-name>

<url-pattern>/diagnostics/diagnoseTrouble</url-pattern>

</servlet-mapping>

a. / the /diagnostics/diagnoseTrouble URL of the document root directory
b. / the /diagnostics/diagnoseTrouble URL of the current directory
c. / any URL in the /diagnostics/diagnoseTrouble directory of the document root directory
d. / any URL in the /diagnostics/diagnoseTrouble directory of the current directory

22.The init method of a servlet class is called

a. / the first time a servlet is requested but before the service method
b. / each time the servlet is requested but before the service method
c. / the first time a servlet is requested but after the service method
d. / each time the servlet is requested but after the service method

23.If you use a servlet instead of a JSP,

a. / the resulting web page won’t be generated as rapidly
b. / it’s harder to code the HTML for the web page
c. / it’s harder to get the parameters from the request object
d. / all of the above

24.Which of the following is NOT part of an HTTP URL:

a. / Protocol
b. / path
c. / node
d. / None of the above

FILL IN THE MISSING BLANKS(28%)

Select the best fit from the following word, or words: request, response, request parameters, WEB-INF, META-INF, document root, tomcat, doPost, doGet, JSP, servlet, JavaBean, AJAX, DOM, web.xml, ServletContext, init, JavaScript, localhost, localhost, webapps, deployment descriptor, servlet reloading, HTTP,

1.To run a web application on your own PC, you can use the ______keyword to refer to the host machine.

2.One way to deploy a web application is to copy a WAR file into Tomcat’s ______directory.

3.The web.xml file is known as the ______for a web application.

4.The web.xml file is always stored in the ______subdirectory of an application.

5.To enable Tomcat to automatically check for servlets that have changed, you should enable ______.

6.______makes it possible to update part of a web page with data from a web server without having to reload the entire page.

7.You can use getRealPath method of a/an ______object to get the absolute path to a file that’s part of a web application.