Total time: 75 minutes. Each problem is worth exactly 1 point unless otherwise specified.

CSCI A348/548
Midterm Exam

Fall 2000

Motto for the exam: "Education is what remains after you forget everything you learned in school."

Write your name or username here: _______________________________. Good luck and do well!

Correct answers appear written in blue.

1. What is the primary function of an HTTP server?
to display HTML documents
to process HTTP requests
to run CGI scripts
all of the above
none of the above
The primary function of an HTTP server is to service client requests for documents. It waits for HTTP requests and then returns data for each one. An HTTP daemon provides an HTTP service. It allows a server to support client requests for documents. It generates errors when invalid requests are received or when a document cannot be found. The Web server process also generates log files of requests, errors, and other information.
2. What is the primary function of a Web browser?
to send e-mail
to read news
to display HTML documents
all of the above
to run CGI scripts
none of the above
The primary function of a Web browser is to display HTML documents. Although it can be used to view local documents on a hard drive, it is normally used as a client to retrieve documents from an HTTP server. Although browser software has expanded over the past few years to include such services as e-mail and news, its primary function is to format HTML documents for display.
3. A web server is which of the following?
software hardware both
Technically, a Web server consists of two pieces: the hardware and the software. The machine itself is often called a Web server, and the HTTP daemon is also known as a Web server. Still you can have 'your web server' running on the same machine as 'my server' thus sharing the hardware resources but not the programs. Choosing the first answer without any qualifications or notes, should give you most of the credit, and you should get full credit if you mentioned that "it needs hardware, just not dedicated hardware" or something to this effect. ,
4. A web server can run on just about any type of machine, not just a huge, expensive server.
true false
Although you probably wouldn't want to run your corporate Web site from a server the size of a matchbook, it is possible to run a Web server on even the smallest computers. Even relatively old and slow computers can do a good job of serving Web pages for a small site.
5. A browser utilizes which of the following technologies? (Choose all that apply).
A network A Web server A phone line HTTP
The browser only deals with HTTP directly, so that's the main emphasis of this question. It does use a network and talks to a Web server (indirectly). A phone line is not a necessity to use with a browser, but it may be needed to connect to your ISP.
6. Which of the following may be a reason for running a Web server on a port other than port 80?
a) You don't have access to port 80 (since you are not root).
b) You are running multiple Web servers on the same machine.
c) You don't have enough memory.
d) Both a) and b).
e) All of the above.
The amount of memory has nothing to do with ports.
7. A server can also be a client.

true false
The server machine that runs a Web server might also be used by users to browse the Web, for example. But that only means we can run clients on any hardware. More specifically, your web server could start a CGI script that retrieves some data over the network from another (database) server. Then it produces the output. The result is passed to the Web server which sends it back to the client. Through the CGI script the Web server acted as a client to a third-tier (back-end) server.
8. An HTML file contains
Text Images Both text and images Binary data
An HTML file only contains text; images are not part of the document. The HTML contains tags that reference images (which are subsequently being retrieved by the browser).
9. Which of the following types of tools cannot be used to create hypertext documents?
A simple text editor
A word processing program
An automatic HTML generator
A graphics utility
All of these are capable of creating hypertext documents
Most graphics (drawing) programs will not output HTML; they only create graphics images. Those images can be used from a hypertext document, however.
10. Mime types are important for which of the following reasons?
They allow the browser and server to communicate
They tell applications what kinds of documents are being sent
They speed the transmission of binary files
FTP uses them to determine how to transfer files
MIME types are really used only to allow applications to determine the type of document they are dealing with.
11. What is the MIME type of an HTML document?
none of the above
The media type is text, the subtype is html.
12. Why is a simple text editor useful to a webmaster?
It generates plain text files with no special characters
Text editors are generally available on all platforms
In many cases it's quicker than using a large application
All of the above
A simple text editor is not useful to a webmaster
13. Which are the three parts of every HTTP transaction?

A request or response line, a header section, and an entity body.

A request line is sent as the first line of all HTTP requests. The browser then sends any relevant headers. An entity body is sent only when data other than the headers needs to be sent to the server. A GET method does not usually contain an entity body, but a POST or PUT method usually does.

A response line is sent as the first line of all HTTP responses. The server then sends any relevant headers and the entity body. The entity body is usually the document requested, but it could also be error information if an error occured while trying to retrieve the document.


14. Name the three most widely used request methods.


Currently, these are the most widely used request methods. As new features are added to the HTTP specification, other methods may become more widely used.


15. What is the difference between a HEAD and a GET?

The HEAD method is used to return the header section for a specific document; it does not return the document itself.

16. What header is sent by the server so that the browser can determine what type of content is being returned?

The Content-type: header indicates the media type of the data contained in the entity body. The server determines the type of data by looking at the file extension and referencing the MIME types file. Server scripts are responsible for properly labelling their output themselves.

17. What is the first thing that is passed to the server when an HTTP transaction begins?

The request line
The response line
The entity body
The transaction line
All of the above could be sent first
None of the above could be sent first
The request line is sent first, containing
  1. the request method,
  2. the requested resource, and
  3. the protocol version.
18. The GET method is the only method that retrieves information from the server.

true false
The HEAD method is also used to retrieve information from the server, although it doesn't return an entire document, only information about the document.
19. To publish files to a Web server, you should have a user account.

true false
You will normally require some type of login and password to be able to put files on the Web server machine. You can get credit for choosing the other answer if you clearly identify under what realistic circumstances you can publish without logging in.
20. If the permissions allow it, users can modify other user's files.

true false
Users can give other people permission to modify their files. Be careful.
21. What is the difference between an absolute pathname and a relative pathname?

An absolute pathname always starts with the root directory, in most cases a slash or the backslash. It specifies the exact location of a file in the file system. A relative pathname is used to specify a file with regard to the current directory. A relative pathname does not start with a slash; it can start with a directory name (including dot-dot) or a filename.

22. Which of the following are absolute paths? (Check all that apply).

23. Which of the following are relative paths? (Check all that apply).

24. Which of the following is a document root directory?

It depends on how the web server is configured
25. Directory indexing allows the Web server to generate a page containing a list of files in a directory automatically if no default document is specified.

Which of the following names have we used in this class for default documents?

All of the above
26. Filenames are not important because users will always be accessing your site through Web pages, not by typing in filenames directly.
true false
27. Directories are limited to the number of files they can contain, so you should put only a few files in each directory.
true false
28. To access a file named "A+WeirD&Filename.html" over the web you need to refer to it as:
None of the above
This file cannot be accessed over the web.
29. The filename MyFile.html is the same as myfile.html on a Unix server.

true false
30. What features are attributed to the Apache web server? (Choose all that apply)

Easy-to-use GUI configuration
It currently uses text-based configuration files and it's free.
31. When testing Web servers, only a single server may be set up on a machine.

true false
32. Free Web server software is not good enough to run Enterprise-class Web servers.

true false
Apache is used on many large sites.
33. What is CGI?
A programming language
An API (Application Programming Interface)
A method for a Web server to communicate with other programs
All of the above
None of the above
34. Forms are part of CGI.
true false
35. Forms are the only way that queries can be sent to a CGI program.

true false
36. What is the benefit of using JavaScript code in an HTML document?

Client-side scripting languages such as JavaScript are tightly integrated into the browser. [...] A server-side program cannot do anything with the browser directly; [...]

If a JavaScript program is written to respond to user interaction, it can provide very quick responses. [...]

Although there is no limit to the size of JavaScript programs, it is usually a good idea to keep them short. A page with an excessive amount of JavaScript code may take longer to load. Maintaining pages of JavaScript code can become a nightmare; design your pages and write your code with maintenance in mind.


Consider the following JavaScript code:

function a(x, y) {
  return x + y;
function b(x, y) {
  return x * y;
// a = b;
document.write(a(a(3, 4), b(3, 4))); 
Assume it's part of an HTML file, and is properly included in it with <SCRIPT> tags in it.

37. (2 points) What will the browser display when you load the page in it.


38. How does the answer change if you uncomment the line currently commented?


39. (2 points) Consider the following JavaScript code:

function a(x, y) {  
  return y(x, x);
function b(x, y) {  
  return x - y;
document.write(a(b(2, 4), b)); 
What will the browser display when you load the page in it?


40. (2 points) How do you find out if your server is running, from the Unix prompt?

ps -ef | grep username | grep httpd

Or something to that effect.


41. (2 points) What's in the file?


42. (2 points) What's ENV and where did we use it? What does it contain?


43. (8 points) Here's a form:

  <body bgcolor=white>
    <form method="POST" action="/cgi-bin/alpha">
      <input type=text name="a"> 
      <input type=text name="c"> 
      <input type="submit" value="Proceed">
Finish alpha that prints the values associated with a and b. (Write the code that should go on the three missing lines plus one other spot).


} else {
  read(STDIN, __$in___, $ENV{CONTENT_LENGTH});

print "Content-type: text/html\n\n";

@in = split(/&/, $in); 

foreach $e (@in) {
  ($name, $value) = split(/=/, $e);

  $name =~ s/%(..)/chr(hex($1))/ge;
  $value =~ s/%(..)/chr(hex($1))/ge;
  print $name, "=(", $value, ")";
44. What, in your own words, is the difference between the Internet and the World Wide Web (if any)?

The Internet is the global network allowing computers of all sizes, from many different computer vendors, running totally different operating systems, to communicate with each other. It operates using the TCP/IP protocol suite, which provides the transport and network layers of Internet operation.

The World Wide Web is the most popular Internet application, merging hypertext and internetworking paradigms to allow user access to multimedia data. It operates using the HTTP protocol, which is one of the many application layers of the Internet.


45. (2 points) Briefly explain the event handling mechanism in JavaScript.


46. (2 points) What is the output of the following simple Perl program?

@a = (1, 2, 3, 4);
print $#a;
47. (2 points) What is the output of the following simple Perl program?

$a = "There's a tomato in every automaton.";
$a =~ s/tomato/**/g;
print $a;
48. (2 points) What is the output of the following simple Perl program?

$a = "My goodness!"; 
$a =~ s/(.)/($1)/;
print $a;     
49. (2 points) What is the output of the following simple Perl program?

$a = "My goodness!"; 
$a =~ s/(.)/($1)/g;
print $a;     
Note the g at the end in this one!

50. (2 points) What is the output of the following simple Perl program?

$a = "hOoB!y"; 
$a =~ s/(.)(.)/$2$1/g;
print $a;     
51. (2 points) What is the output of the following simple Perl program?

$a = "12345"; 
$a =~ s/(..)/$1+1/g;
print $a;     
52. (2 points) What is the output of the following simple Perl program?

$a = "12345"; 
$a =~ s/(..)/$1+1/ge;
print $a;     
Again, note the extra e at the end!
Last updated on October 19, 2000, by Adrian German for A348/A548.