Übungsmaterial

HTML und XHTML

Datei erste.html:

<html>
<head>
<title>Meine erste HTML Seite</title>
</head>
<body bgcolor="yellow" >
<h1>Die erste HTML Seite von Heinz Kredel</h1>
<p>
Hier steht ein kleiner unbedeutender <strong>Text</strong>.
Der Text geht in den n&auml;chsten Satz.
Bis sich schliesslich der <em>dritte</em> 
<em>Satz</em> auftut.
</p>
<p>
Ein Absatz mit einem Link zu meiner Einrichtung 
<a href="http://www.uni-mannheim.de/">Universität Mannheim</a>.
In diesen Satz ist ein Link auf die 
<a href="zweite.html" target="zweite" >zweite Seite</a>.
</p>
</body>
</html>

Datei zweite.html:

<html>
<head>
<title>Meine zweite HTML Seite</title>
</head>
<body bgcolor="aqua" >
<h1>Die zweite HTML Seite von Heinz Kredel</h1>
<p>
Hier steht ein kleiner unbedeutender <strong>Text</strong>.
Der Text geht in den nächsten Satz.
Bis sich schliesslich der <em>dritte</em> 
<em>Satz</em> auftut.
</p>
<p>
Ein Absatz mit einem Link zu meiner Einrichtung 
<a href="http://www.uni-mannheim.de/">Universität Mannheim</a>.
</p>
<p align="center">
   <img src="univer-w.gif" alt="Uni-Logo" />
</p>
<p align="center">
   <a href="http://www.uni-mannheim.de/"
      ><img src="http://www.uni-mannheim.de/bilder/univer-w.gif" 
            alt="Uni-Logo" /></a>
</p>
</body>
</html>

Datei formular.html:

<html>
<head>
<title>HTML Seite mit Formular</title>
</head>
<body bgcolor="lime" >
<h1>Eine HTML Seite mit Formular</h1>

<form action="http://trumpf-10.rz.uni-mannheim.de/~kredel/ex1.phtml" >

<p>
Vorname: 
<input type="text" size="30" name="my_name" />
</p>
<p>
Familienname: 
<input type="text" size="30" name="my_status" />
</p>
<p>
Mittagessen:
<input type="radio" name="my_hobby" value="la" /> Lasagne
<input type="radio" name="my_hobby" value="br" /> Bratwurst
<input type="radio" name="my_hobby" value="sa" /> Salat XY
</p>
<p>
Sonstiges:
<input type="checkbox" name="my_age" value="su" /> Suppe
<input type="checkbox" name="my_age" value="de" /> Desert
<input type="checkbox" name="my_age" value="ca" /> Kaffee
</p>

<p>
<input type="reset" value="Oooops" />
<input type="submit" value="Ab die Post!" />
</p>
</form>

</body>
</html>

Datei tabelle.html:

<html>
<head>
<title>HTML Seite mit Formular und Tabelle</title>
</head>
<body bgcolor="lime" >
<h1>Eine HTML Seite mit Formular und Tabelle</h1>

<form action="http://trumpf-10.rz.uni-mannheim.de/~kredel/ex1.phtml" >
<table border="0" cellpadding="5" cellspacing="10"
       summary="Layout only" >
<tr>
<td align="right">Vorname:</td>
<td><input type="text" size="30" name="my_name" /></td>
</tr>
<tr>
<td align="right">Familienname:</td> 
<td><input type="text" size="30" name="my_status" /></td>
</tr>
<tr>
<td align="right">Mittagessen:</td>
<td>
<input type="radio" name="my_hobby" value="la" /> Lasagne
<input type="radio" name="my_hobby" value="br" /> Bratwurst
<input type="radio" name="my_hobby" value="sa" /> Salat XY
</td>
</tr>
<tr>
<td align="right">Sonstiges:</td>
<td>
<input type="checkbox" name="my_age" value="su" /> Suppe
<input type="checkbox" name="my_age" value="de" /> Desert
<input type="checkbox" name="my_age" value="ca" /> Kaffee
</td>
</tr>
<tr>
<td valign="top" align="right" >
<input type="reset" value="Oooops" />
</td>
<td valign="top" >
<input type="submit" value="Ab die Post!" />
</td>
<td></td>
</tr>
</table>
</form>

</body>
</html>

CSS

Kurs 1:

index.html:

<html>
<head>
<title>Der Einstieg</title>
<style type="text/css" >
 body { background-color: lime;
        font-size: 150%;
        font-style: italic;
      }
 h1   { color: red; 
      }
 h2   { color: yellow;
        text-decoration: underline;
      }
 em   { background-color: olive;
      }
 h2 em { background-color: blue;
       }
 p    { font-family: Verdana serif;
      }
 a:link { color: red; 
 }
 a:visited { color: grey; 
 }
</style>

</head>
<body bgcolor="white" >
<h1>Der Einstieg</h1>

<h2>Die Dateien vom <em>fünften</em> Tag</h2>

<p>
Die folgen Dateien haben wir unter <em>größten</em> 
Anstrengungen mit zwei oder mehr Fingern eingetippt.
</p>
 
<ul>
<li><a href="erste.html">erste.html</a></li>
<li><a href="zweite.html">zweite.html</a></li>
<li><a href="formular.html">formular.html</a></li>
<li><a href="tabelle.html">tabelle.html</a></li>
</ul>

<h2>Die Dateien vom sechsten Tag</h2>
<ul>
<li><a href="java/Screen.java">Screen.java</a></li>
<li><a href="java/KeyBoard.java">KeyBoard.java</a></li>
<li><a href="java/DateiEin.java">DateiEin.java</a></li>
<li><a href="java/DateiAus.java">DateiAus.java</a></li>
<li><a href="java/DateiDran.java">DateiDran.java</a></li>
<li><a href="java/Cat.java">Cat.java</a></li>
<li><a href="java/Grep.java">Grep.java</a></li>
<li><a href="java/Grep2.java">Grep2.java</a></li>
<li><a href="java/Grep3.java">Grep3.java</a></li>
</ul>

<h2>Die Dateien vom dritten und vierten Tag</h2>
<ul>
<li><a href="intro/Datum1.java">Datum1.java</a></li>
<li><a href="intro/Datum2.java">Datum2.java</a></li>
<li><a href="intro/Datum3.java">Datum3.java</a></li>
<li><a href="intro/Datum4.java">Datum4.java</a></li>
<li><a href="intro/DatumTest1.java">DatumTest1.java</a></li>
<li><a href="intro/DatumTest2.java">DatumTest2.java</a></li>
<li><a href="intro/DatumTest3.java">DatumTest3.java</a></li>
<li><a href="intro/DatumTest4.java">DatumTest4.java</a></li>
<li><a href="intro/DatumTest5.java">DatumTest5.java</a></li>
<li><a href="intro/EingabeBsp1.java">EingabeBsp.java</a></li>
<li><a href="intro/MFeldBsp1.java">MFeldBsp1.java</a></li>
<li><a href="intro/SchleifenBsp.java">SchleifenBsp.java</a></li>
<li><a href="intro/SchleifenBsp2.java">SchleifenBsp2.java</a></li>
<li><a href="intro/SwitchBsp.java">SwitchBsp.java</a></li>
<li><a href="intro/Vererbung.java">Vererbung.java</a></li>
<li><a href="intro/StringBsp1.java">StringBsp1.java</a></li>
<li><a href="intro/StringBsp2.java">StringBsp2.java</a></li>
<li><a href="intro/StringBsp3.java">StringBsp3.java</a></li>
<li><a href="intro/StringBsp4.java">StringBsp4.java</a></li>
</ul>

</body>
</html>

Kurs 2:

index.html:

<html>

<head>
<title>Meine erste Index Seite</title>
<style type="text/css" >
  body {
       background-color: lime; 
       font-family: Verdana,Helvetica,sans-serif;
       font-size: 18pt;
  }
  h1 { color: red; }
  h2 { background-color: white; 
       color: #00ff00;
  }
  p  { color: rgb(0,0,255); }
  em, strong { font-weight: bold; 
               font-style: normal;
  }
  p em {
    font-family: Times;
  }
  a:link { 
       font-weight: bold;
  }
  a:visited {
       font-weight: bold;
  }
  .bemerkung {
       background-color: yellow;
  }
</style>
</head>

<body bgcolor="yellow" >
<h1>Eingang zur Web-Site</h1>
<h2>Die Arbeit vom fünften Tag</h2>
<p>Die folgenden Dateien haben wir
<strong>gestern</strong>
mit dem grössten <em>Vergnügen</em> eingetippt.
</p>
<ul>
<li>Die <a href="erste.html">erste</a> Datei.
</li>
<li>Die <a href="zweite.html">zweite</a> Datei.
</li>
<li>Die <a href="formular.html">formular</a>-Datei.
</li>
<li>Die <a href="tabelle.html">tabelle</a>-Datei.
</li>
<li>Die <a href="dritte.phtml">1.PHP</a>-Datei.
</li>
<li>Die <a href="vierte.phtml">2.PHP</a>-Datei.
</li>
<li>
  <ul>
  <li>Punkt 1</li>
  <li>Punkt 2</li>
  </ul>
</li>
</ul>
<p class="bemerkung">
Die folgenden Dateien haben wir gestern
unter den grössten Anstrengungen eingetippt.
</p>

</body>

</html>

PHP

Kurs 1:

dritte.phtml:

<?php
$filename=$SCRIPT_FILENAME;
$counter_start="1";
function mycounter() {
        global $filename, $counter_start;
        $counter_dir="/tmp/";
        $counter_db=$counter_dir . "zaehler.dbm";
        if (file_exists("$counter_db")) {
           $db=dba_open($counter_db,"w","gdbm");
           if ( dba_exists($filename,$db) ) {
              $cnt = dba_fetch($filename,$db);
              if ($counter_start=="1") { $cnt++; }
              else { $cnt=$counter_start; }
              dba_replace($filename,$cnt,$db);
           }
           else {
               $cnt=$counter_start;
               dba_insert($filename,$cnt,$db);
           }
           dba_close($db);
           return "$cnt";
        }
        else {
           echo "Attempt to create file: " . $counter_db;
           $cnt=$counter_start;
           $db=dba_open($counter_db,"n","gdbm");
           dba_insert($filename,$cnt,$db);
           dba_close($db);
           return "$cnt";
        }
}
?>
<html>
<head>
<title>Eine Testseite von H. Kredel mit PHP</title>
<style type="text/css" >
 body { background-color: lime; font-size: 200%; }
</style>
</head>
<body>
<h1>Eine Testseite von H. Kredel mit PHP</h1>

<?php 
  print "<p>variable = " . $variable . "</p>";
  print "<p>Aufrufe: " . mycounter() . "</p>";
  ?>

<?php 
  if ( $variable == "" ) {
     print "<p>Hallo, bist du neu hier ?</p>";
  } else {
     print "<p>Hallo " . $variable . "! </p>"; 
  }
  ?>

<form action="dritte.phtml" method="POST" >
<p>Name: 
<input type="text" size="20" name="variable" 
    value="<?php print $variable; ?>"
  />
</p>
<p>
Passwort:
<input type="password" size="20" name="geheim" />
</p>
<p>
<input type="submit" value="Mach mal" />
</p>
</form>

<?php 
 if ( $variable == "hk" & $geheim == "4711" ):  
 ?>
<p>Hier steht eine geheime Information</p>
<?php
 endif;
 ?>

<?php 
  print "<p>Hallo aus PHP</p>"; 
  ?>

<?php
  for ($i = 0; $i < 2; $i++ ) {
      print "<p>Schleifendurchlauf = " . $i . "</p>";
  }
  ?>

<?php print "<p>Browser ist: $HTTP_USER_AGENT</p>"; ?>


</body>
</html>

Kurs 2:

dritte.phtml:

<html>
<head>
<title>Eine Testseite mit PHP</title>
</head>
<body bgcolor="yellow" >
<h1>Eine Testseite mit PHP</h1>

<?php
  print "<p>Hallo wie gehts?</p>\n";
  print "<p>Ergebnis von 7 + 8 = " . (5 . 8) . " </p>\n";
  for ($size=2; $size < 30; $size+=4) {
     print "<p align='center' style='font-family: Times; font-size: " . $size . "pt;' >";
     print "Paragraph mit angepasster Grösse</p>\n"; 
  }
 ?>

</body>
</html>

vierte.phtml:

<html>
<head>
<title>Eine 2. Testseite mit PHP</title>
</head>
<body bgcolor="aqua" >
<h1>Eine 2. Testseite mit PHP</h1>

<form action="vierte.phtml" >
<p>
Wie ist dein Name ?
<input type="text" name="dername" size="30" />
</p>
<p>
Wieviele Iterationen ?
<input type="text" name="iterationen" size="30" />
</p>
<p>
<input type="submit" value="Anmelden" />
</p>
</form>

<?php
  print "<p>Hallo $dername wie gehts?</p>\n";
  
  print "<p>Diese Seite wurde ";
  if ( $iterationen < 0 ) $counter_start = -$iterationen;
  counter();
  print "-mal aufgerufen.</p>\n";

  if ($iterationen > 100) $iterationen=20;
  for ($size=2; $size < $iterationen; $size+=4) {
     print "<p align='center' style='font-family: Times; font-size: " . $size . "pt;' >";
     print "Paragraph mit angepasster Grösse</p>\n"; 
  }
 ?>

</body>
</html>

XML

gene.xml:

<?xml version="1.0" ?>

<!DOCTYPE sequence SYSTEM "sequenz.dtd" >


<sequence id="s7850" type="ra" >

<link type="database" >
  <db href="http://www.genbank.org">Genbank</db> 
</link>


<residues id="r1" >atcgtaagtgggatttgat</residues>
<residues id="r2" >atcggatttgatagcgacgcgca</residues>

</sequence>

sequenz.dtd:

<?xml version="1.0" encoding="iso-8859-1" ?>

<!ELEMENT sequence (link,residues*) >
<!ELEMENT link     (db) >
<!ELEMENT residues (#PCDATA) >
<!ELEMENT db       (#PCDATA) >

<!ATTLIST residues id ID #IMPLIED >
<!ATTLIST sequence id ID #REQUIRED 
               type (dna|rna) #REQUIRED >
		   
<!ATTLIST link     type CDATA #IMPLIED >
<!ATTLIST db       href CDATA #REQUIRED >

Java

Kurs 1:

Cat.java:

import java.io.PrintWriter;

public class Cat {

  public static void main(String[] args) 
   throws Exception {

   Screen out = new Screen();

   if ( args.length == 0 ) {
      out.println("Usage Cat <dateiname>");
      return;
   }
   DateiEin in = new DateiEin( args[0] );

   String einaus = "";
   while ( true ) {
         einaus = in.readLine();       
         if ( einaus == null ) break;
         out.println(einaus);
   }
  }
}

Grep.java:

import java.io.PrintWriter;

public class Grep {

  public static void main(String[] args) 
   throws Exception {

   Screen out = new Screen();

   if ( args.length <= 1 ) {
      out.println("Usage Grep <muster> <dateiname>");
      return;
   }
   String muster = args[0];
   DateiEin in = new DateiEin( args[1] );

   String einaus = "";
   while ( true ) {
         einaus = in.readLine();       
         if ( einaus == null ) break;
         if ( einaus.indexOf(muster) > -1 ) {
            out.println(einaus);
         }
   }
  }
}

Grep2.java:

import java.io.PrintWriter;

public class Grep2 {

  public static void main(String[] args) 
   throws Exception {

   Screen out = new Screen();

   if ( args.length <= 1 ) {
      out.println("Usage Grep "
        + "<muster> <dateiname> [ausgabedatei]");
      return;
   }
   String muster = args[0];
   DateiEin in = new DateiEin( args[1] );

   DateiAus save = null;
   if ( args.length == 3 ) {
      save = new DateiAus( args[2] );
   }

   String einaus = "";
   while ( true ) {
         einaus = in.readLine();       
         if ( einaus == null ) break;
         if ( einaus.indexOf(muster) > -1 ) {
            out.println(einaus);
            if (save != null) save.println(einaus);
         }
   }
   if (save != null) save.flush();
  }
}

Cat.java:

import java.io.PrintWriter;

public class Grep3 {

  public static void main(String[] args) 
   throws Exception {

   PrintWriter out = new Screen();

   if ( args.length <= 1 ) {
      out.println("Usage Grep "
        + "<muster> <dateiname> [ausgabedatei]");
      return;
   }
   String muster = args[0];
   DateiEin in = new DateiEin( args[1] );

   if ( args.length == 3 ) {
      out = new DateiAus( args[2] );
   }

   String einaus = "";
   while ( true ) {
         einaus = in.readLine();       
         if ( einaus == null ) break;
         if ( einaus.indexOf(muster) > -1 ) {
            out.println(einaus);
         }
   }
   out.flush();
  }
}

Kurs 2:

Cat.java:

import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileNotFoundException;

/**
  * UNIX cat Kommando 
  *
 **/ 

public class Cat {

    public static void main(String[] args) {

        Screen sc = new Screen();

        BufferedReader rein = null;
        PrintWriter raus = sc;

	if ( args.length == 0 ) {
	    rein = new KeyBoard();
            onefile(rein,raus);
            return;
	}

        for (int i = 0; i < args.length; i++ ) {
            try {
                rein = new DateiEin(args[i]);
	    } catch (FileNotFoundException e) {
              sc.println("Die Datei " + args[i] + " ist nicht lesbar: "
                          + e.getMessage());
              continue;
	    } catch (IOException e) {
              sc.println("Die Datei " + args[i] + " ist nicht lesbar. "+e);
              continue;
	    }
            onefile(rein,raus);
            try {
	        rein.close();
            } catch (IOException e) {
	             //	    e.printStackTrace();
            }
	}
    }


    private static void onefile(BufferedReader rein, 
                                PrintWriter raus) {
        String ea = "";
        try {
            while ( true ) {
		ea = rein.readLine(); 
	        // sc.println("Eingabe: "+ea);
                if ( ea == null ) break;
                raus.println(ea); 
            }
	} catch (IOException e) {
	    //	    e.printStackTrace();
	} finally {
	    raus.flush();
	}
    }

}

Grep.java:

import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileNotFoundException;

/**
  * UNIX grep Kommando 
  *
 **/ 

public class Grep {

    public static void main(String[] args) {

        Screen sc = new Screen();

        BufferedReader rein = null;
        PrintWriter raus = sc;

        if ( args.length == 0 ) {
	    sc.println("Usage: Grep <string> [eingabe dateien]");
            return;
	}
        String muster = args[0];

	if ( args.length == 1 ) {
	    rein = new KeyBoard();
            onefile(muster,rein,raus);
            return;
	}

        for (int i = 1; i < args.length; i++ ) {
            try {
                rein = new DateiEin(args[i]);
	    } catch (FileNotFoundException e) {
              sc.println("Die Datei " + args[i] + " ist nicht lesbar: "
                          + e.getMessage());
              continue;
	    } catch (IOException e) {
              sc.println("Die Datei " + args[i] + " ist nicht lesbar. "+e);
              continue;
	    }
            onefile(muster,rein,raus);
            try {
	        rein.close();
            } catch (IOException e) {
	             //	    e.printStackTrace();
            }
	}
    }


    private static void onefile(String muster,
                                BufferedReader rein, 
                                PrintWriter raus) {
        String ea = "";
        try {
            while ( true ) {
		ea = rein.readLine(); 
	        // sc.println("Eingabe: "+ea);
                if ( ea == null ) break;
                if ( ea.indexOf(muster) > -1 ) {
                   raus.println(ea);
		}
            }
	} catch (IOException e) {
	    //	    e.printStackTrace();
	} finally {
	    raus.flush();
	}
    }

}

© Universität Mannheim, Rechenzentrum, 1998-2002.

Heinz Kredel
Last modified: Tue Oct 1 12:03:44 CEST 2002