/usr/share/mozart/doc/apptut/node17.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>13 Servlets</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node16.html#chapter.applets"><< Prev</A></TD><TD><A href="node15.html">- Up -</A></TD></TR></TABLE><DIV id="chapter.servlets"><H1><A name="chapter.servlets">13 Servlets</A></H1><P>A <EM>servlet</EM> is a small application that exists on a Web server and that can be invoked by a CGI command. A servlet is usually called a <EM>CGI script</EM>. CGI (Common Gateway Interface) is a protocol that defines how data is passed between a Web server and a servlet. </P><P>A servlet is a program that accepts an input and calculates a result. To be precise, it does the following steps: </P><UL><LI><P>Get the arguments for the servlet by calling <CODE>Application<SPAN class="keyword">.</SPAN>getCgiArgs</CODE>. A standard application would call <CODE>Application<SPAN class="keyword">.</SPAN>getCmdArgs</CODE> for this purpose. The former is used in exactly the same way as the latter, but instead of parsing command line arguments, it parses CGI arguments. </P></LI><LI><P>Calculate the result. </P></LI><LI><P>Print a header on <CODE>stdout</CODE> that defines the content type. The content type tells the Web browser what the type of the result is, so that it knows how to display it. For example, if the servlet outputs HTML, you have to print something like: </P><BLOCKQUOTE class="code"><CODE>'Content-type: text/html\n\n'</CODE></BLOCKQUOTE><P></P><P>(without the quotes). The <CODE>Open<SPAN class="keyword">.</SPAN>html</CODE> class has support for this (see example below). </P></LI><LI><P>Output the real data. For example, text in HTML format.</P></LI></UL><P></P><P>The following example follows this structure. It uses a class <CODE>Open<SPAN class="keyword">.</SPAN>html</CODE> to generate HTML code on the fly. You can test it by sending a URL that looks like this: </P><BLOCKQUOTE class="code"><CODE><SPAN class="string">'http://www.you.edu/~you/small.cgi?number=10&text=Hi'</SPAN></CODE></BLOCKQUOTE><P></P><P>In this example, the value <CODE>10</CODE> is passed for the argument <CODE><SPAN class="string">'number'</SPAN></CODE> and the value <CODE><SPAN class="string">"Hi+Guys"</SPAN></CODE> for the argument <CODE><SPAN class="string">'text'</SPAN></CODE> (in CGI argument syntax, the plus is used to quote a space). </P><BLOCKQUOTE class="code"><CODE><SPAN class="keyword">functor</SPAN> <BR><SPAN class="keyword">import</SPAN> Application Open<BR><SPAN class="keyword">define</SPAN> <BR> %% <SPAN class="comment">Parse the arguments<BR></SPAN> Args={Application<SPAN class="keyword">.</SPAN>getCgiArgs <BR> record(number(single type:int default:0)<BR> text(single type:string default:<SPAN class="string">"none"</SPAN>))}<BR> <BR> %% <SPAN class="comment">A file that supports HTML output<BR></SPAN> Out={New <SPAN class="keyword">class</SPAN> <SPAN class="type">$</SPAN> <BR> <SPAN class="keyword">from</SPAN><SPAN class="type"> Open.file Open.html</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> init(name:stdout)}<BR> <BR> %% <SPAN class="comment">Print MIME content header<BR></SPAN> {Out header}<BR> <BR> %% <SPAN class="comment">Print HTML output<BR></SPAN> {Out tag(html(head(title(<SPAN class="string">'My First CGI'</SPAN>))<BR> body(bgcolor:<SPAN class="string">'#f0f0e0'</SPAN> <BR> h1(<SPAN class="string">'My First CGI'</SPAN>)<BR> p(<SPAN class="string">'The number is: '</SPAN><SPAN class="keyword">#</SPAN>Args<SPAN class="keyword">.</SPAN>number)<BR> p(<SPAN class="string">'The text is: '</SPAN><SPAN class="keyword">#</SPAN>Args<SPAN class="keyword">.</SPAN>text))))}<BR> <BR> %% <SPAN class="comment">Terminate<BR></SPAN> {Application<SPAN class="keyword">.</SPAN>exit 0}<BR><SPAN class="keyword">end</SPAN></CODE></BLOCKQUOTE><P> </P><P>In order to compile this servlet, you have to do: </P><BLOCKQUOTE class="code"><CODE>ozc --execpath=</CODE><I>OZHOME</I><CODE>/bin/ozengine -x small.oz -o small.cgi</CODE></BLOCKQUOTE><P></P><P>Where <I>OZHOME</I> denotes the installation directory of the Mozart system. The <CODE>execpath</CODE> argument is needed because the servlet needs an absolute path. Servlets are normally executed by the Web server in an extremely minimal user environment. The user is typically called <CODE>nouser</CODE> or <CODE>www</CODE> and has almost no rights. In particular you cannot expect the Mozart system to be in the path of the user! This is why you need an absolute pathname when compiling the servlet. </P><P>On a Unix system, you can more simply invoke: </P><BLOCKQUOTE class="code"><CODE>ozc --execpath=`which ozengine` -x small.oz -o small.cgi</CODE></BLOCKQUOTE><P> </P><P>The final step is to install the servlet in your Web server. For this you should contact your local Web site administrator. </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node16.html#chapter.applets"><< Prev</A></TD><TD><A href="node15.html">- Up -</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~duchier/">Denys Duchier</A>, <A href="http://www.ps.uni-sb.de/~kornstae/">Leif Kornstaedt</A> and <A href="http://www.ps.uni-sb.de/~schulte/">Christian Schulte</A><BR><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|