This is our first CGI-Perl example
<a href =
"">
Click here to run the CGI program, reply.pl
</a>
</body>
</html>
- The connection from a CGI program back to the requesting browser is through standard
output, usually through the server
- The HTTP header needs only the content type, followed by a blank line, as is created
with:
print "Content-type: text/html \n\n";
#!/usr/local/bin/perl
# reply.pl – a CGI program that returns a
# greeting to the user
print "Content-type: text/html \n\n",
"<html> <head> \n",
"<title> reply.pl example </title>",
" </head> \n", "<body> \n",
"<h1> Greetings from your Web server!",
" </h1> \n </body> </html> \n";
Query string format

Programming the WEB
10CS73
DEPT. OF CSE, SJBIT
Page 152
In World Wide Web
, a
query string
is the part of a Uniform Resource Locator
(URL)
that contains data to be passed to web applications such as CGI
programs.
The
Mozilla
URL
location
bar
showing
an
URL
with
the
query
string
title=Main_page&action=raw
When a web page
is requested via the Hypertext Transfer Protocol
, the server locates a
file in its file system
based on the requested URL
. This file may be a regular file or a
program. In the second case, the server may (depending on its configuration) run the
program, sending its output as the required page. The query string is a part of the URL
which is passed to the program. Its use permits data to be passed from the HTTP client
(often a web browser
) to the program which generates the web page.
Structure
A typical URL containing a query string is as follows:
When a server receives a request for such a page, it runs a program (if configured to do
so), passing the
query_string
unchanged to the program. The question mark is used as a
separator and is not part of the query string.
A link in a web page may have a URL that contains a query string. However, the main
use of query strings is to contain the content of an HTML form, also known as web form
.
In particular, when a form containing the fields
field
1
,
field
2
,
field
3
is submitted, the content
of the fields is encoded as a query string as follows:
field
1
=value
1
&field
2
=value
2
&field
3
=value
3
...
The query string is composed of a series of field-value pairs.
The field-value pairs are each separated by an equal sign
.
The series of pairs is separated by the ampersand
, '&' or semicolon
, ';'.
For each field
of the form, the query string contains a pair field=value. Web forms may
include fields that are not visible to the user; these fields are included in the query string
when the form is submitted
This convention is a W3C
recommendation. W3C recommends that all web servers
support semicolon
separators in the place of ampersand
separators.

Programming the WEB
10CS73
DEPT. OF CSE, SJBIT
Page 153
Technically, the form content is only encoded as a query string when the form
submission method is GET
. The same encoding is used by default when the submission
method is POST
, but the result is not sent as a query string, that is, is not added to the
action URL of the form. Rather, the string is sent as the body of the request.


You've reached the end of your free preview.
Want to read all 159 pages?
- Winter '17
- Shwetha CH
- World Wide Web