With server-side applications, you can:
HTTP server software can be extended to incorporate a number of languages.
<html>
<head><title>Saying Hello</title></head>
<body>
<h1>Hello World!</h1>
</body>
</html>
<html>
<head>
<title>Saying Hello</title>
<script language="Javascript">
<!--
function message ()
{
document.write("<h1>Hello World!</h1>");
document.close();
}
// -->
</script>
</head>
<body onload="message(); return true">
</body>
</html>
Requires that the server be appropriately configured. On wyrd.hood.edu, files must have the extension .shtml
<html>
<head>
<title><!--#include file="title.txt" --></title>
</head>
<body>
<h1><!--#include file="message.txt" --></h1>
</body>
</html>
where title.txt contains "Saying Hello" and message.txt contains "Hello !"
Requires that the server be appropriately configured. On wyrd.hood.edu, files must have the extension .cgi and must be executable. There are many language choices, including C, C++, Python, BASIC, etc. Any programming language can be used as long as it can read from standard input and write to standard output.
#!/bin/sh
echo -e "Content-type: text/html\n\n"
title="Saying Hello"
message="Hello World!"
echo "<html>"
echo "<head><title>$title</title></head>"
echo "<body>"
echo "<h1>$message</h1>"
echo "</body>"
echo "</html>"
echo -e "\n"
#!/usr/bin/perl
$title="Saying Hello";
$message="Hello World!";
print "Content-type: text/html\n\n";
print "
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$message</h1>
</body>
</html>
";
Perl and Python applications can be made much faster by adding the mod_perl and mod_python modules to Apache. These embed the interpreters in the server, saving the step of externally running the program.
Requires that the server be appropriately configured
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Saying Hello";
String message = "Hello World!";
out.println("<html>");
out.println("<head><title>" + title + "</title></head>");
out.println("<body>")
out.println("<h1>" + message + "</h1>")
out.println("</body>");
out.println("</html>");
out.close();
}
}
Requires that the server be appropriately configured. On wyrd.hood.edu, files must have the extension .php.
<?php
$title = "Saying Hello";
$message = "Hello World!";
?>
<html>
<head>
<title><?php print($title) ?></title>
</head>
<body>
<h1><?php print($message) ?></h1>
</body>
</html>
The phpinfo() library function dumps lots and lots of information about the environment.
Example 2. Processing a form. In this example, PHP code is embedded in the HTML document, but also prints some HTML.
There are many PHP tutorials on the Web, including at the official PHP site and at W3Schools.
Hood College Department of Computer Science: Course materials © 1997-2006 by Elizabeth Chang.