50
CHAPTER 4. SCHEME SERVLETS
4.3
Interacting with HTTP headers
Another example of a servlet is the following which sends back a message to the
browser (using the HTTP protocol) telling it to visit another page instead:
(.sendRedirect response "http://www.nsf.gov")
Visiting this page in a browser will bring you directly to the web page of the
National Science Foundation. In this example, the scheme expression that is
evaluated has an operator .sendRedirect and two operands: response and
"http://www.nsf.gov". The first operand is a special one that refers to the
page that is sent back to the browser. The second operator is a string of char 
acters which is indicated by the enclosing double quotes. There are two other
 special  symbols used by the scheme server: request and httpservlet. The
request symbol can be used to get information about the current request. For
example, the IP address of the browser that is visiting the current page can be
returned using the following servlet:
; yourURL.servlet
(.getRemoteAddr request)
Visiting this page with your browser will return your current IP address. If you
are running the server on your own machine, it will probably return the  loop
back  IP address:
127.0.0.1
You should try the examples in this section with your own server and browser.
Exercise 3 Try out servlets that report on the client's CPU and operating sys 
tem using the Scheme calls
(.getHeader request "ua os")
and
(.getHeader request "ua cpu")
4.4
Quasi strings
The simplest type of useful servlet is one which just returns the same HTML
each time to the user. These servlets are written as standard HTML files except
that the file name must end in  .servlet  and the HTML ust be enclosed in a
pair of curly braces.
{Simple servlet

This is a simple servlet

it has no dynamic content!
}




Php Web Hosting Introduction to Interactive Web Design Php Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.