Server Side Technologies - Quiz Explanation
The correct answers are indicated below, along with the text that explains the correct answers.
1.
A Web servlet is:
Please select the best answer.
A.
An applet that has been installed on a Web server
B.
Any class that extends
java.servlet.Servlet
C.
Any class that extends
javax.servlet.http.HttpServlet
D.
Any class that implements a
doGet()
method
The correct answer is C.
A Java servlet is a class that extends the Java extension class HttpServlet, found in the
javax.servlet.http
package.
A is incorrect because applets are very different from servlets and cannot handle GET requests just because they are installed on a server. B is incorrect because there are no servlet classes in the
java
hierarchy. D is incorrect because there are other methods to be implemented: classes that extend HttpServlet inherit default versions of those methods.
2.
A big disadvantage of executing a program on the Web server through a server side include is:
Please select the best answer.
A.
A poorly written program can be insecure, or even crash the Web server
B.
Such programs cannot be written in Java
C.
The look and feel of your Web site must be maintained within the programs code
D.
Server side include execs cannot access a database
The correct answer is A.
Executing a program through server side includes can have serious consequences for a Web server.
B is incorrect because these programs can be written in any language, including Java.
C is incorrect because ordinary HTML can be written around the include, removing a dependency on your look and feel from the code.
D is incorrect because these programs can perform any task at all, including database access.
3.
ASP pages mix raw HTML with little snippets of code that are executed on the server, with the resulting output sent back to the browser. These snippets can be written in:
Please select the best answer.
A.
Any language at all
B.
Any scripting language, such as Perl, Javascript, or VBscript
C.
Either Javascript or VBscript
D.
VBscript only.
The correct answer is C.
ASP code, mixed with HTML, can be written in VBscript or Javascript. A is incorrect because other languages are not usable in ASP pages. B is incorrect because not all scripting languages can be used. Perl cannot be used, for example. D is incorrect because VBscript is not the only usable language: Javascript can be used instead.
4.
If your user needs to run a CGI program or script, the Web browser will:
Please select the best answer.
A.
Send a GET request to the server, using the script name as the requested file name
B.
Send a CGI request to the server, using the script name as the requested file name
C.
Send a CGI request to the server, which can automatically determine the script name
D.
Send a script request to the server, using the script name as the requested file name
The correct answer is A.
The browser can request HTML from the server using GET whether the HTML comes from a file or a CGI program. B and C are incorrect because there is no CGI request in HTTP. D is incorrect because there is no script request in HTTP.
5.
What do CGI, SSI, ASP, and servlets have in common?
Please select the best answer.
A.
They can execute on the client or the server for maximum flexibility.
B.
They execute on the server, and interact with other server programs.
C.
They are easy and quick to learn
D.
They are efficient and scale well as the number of visitors to your site increases.
The correct answer is B.
CGI, SSI, ASP and servlets are all server-side technologies. They can read and write server files, and interact with database or email programs that are running on the Web server machine. This gives them tremendous power.
A is incorrect because none of these technologies can execute on the client.
C is incorrect because all four take some time to master, especially CGI Perl scripts. Servlets are probably the quickest technology to learn for those who already know Java. D is incorrect because CGI and SSI are notorious for inefficiency and poor scaling. Servlets scale beautifully.
6.
Because servlets are written in Java, a number of powerful features are available from within your code.
Which of the following is not simplified by using Java Web servlets?
Please select the best answer.
A.
Memory management
B.
Threading
C.
Database access
D.
User interaction
The correct answer is D.
Using the Java language will not help you to interact with your user, because servlets arent interactive. All the information they need to run is delivered by the browser in the GET request, and all the output for the user is written out at once. A is incorrect because Java provides powerful memory management and garbage collection as part of the base language.
B is incorrect because threading is part of the standard Java class library. C is incorrect because JDBC simplifies database access.
7.
A Java Web servlet is a class that extends
javax.servlet.http.HttpServlet
. One of the important methods of the superclass that your servlet class should override is:
Please select the best answer.
A.
Get()
B.
doGet()
C.
handleGet()
D.
DoGet()
The correct answer is B.
The doGet() method of your servlet class will be called when the Web server recieves a GET request for your servlet. A, C, and D are incorrect because the function name is doGet() with a lowercase D.
8.
If more than one user wants to run a servlet on your system:
Please select the best answer.
A.
The second one will receive an error message
B.
The second one will have to wait until the first one is completely finished
C.
The system will start a second copy of the servlet and each users request will execute in a different copy
D.
The system will use threading to let both requests share a single copy of the servlet in memory.
The correct answer is D.
One of the reasons that servlets scale so well is that only one copy is in memory, even when several requests occur at once. Threading handles the sharing and turn-taking issues for you. A is incorrect because no error messages are sent when servlets are shared. B is incorrect because two requests can be handled at the same time. C is incorrect because two copies will not be created.
9.
If you write your servlet spectacularly badly, so that it divides by zero, or in some other way encounters a fatal error:
Please select the best answer.
A.
The Web server will be locked up until someone clears your servlet
B.
The Web server will crash and have to be rebooted
C.
No serious consequences will occur
D.
The user will receive an error message from the web server explaining the exception that was thrown
The correct answer is C.
Most errors that are fatal in other programming languages trigger exceptions in Java. If you dont catch the exception, your servlet will fail to complete the tasks you set for it, but it cannot crash or lock up the Web server, or deliver error messages to the user that you didnt plan for yourself.