Spring Semester 2005

Script for individual appointments to discuss the Midterm Exam


Tue May 3
Final Exam today (in LH102) @7:15-9:15PM

Thu-Mon Apr 28-May 2
Please make an appointment next week to discuss your final grade.

Code Walk for Lab Eleven (if you want to make it a project).

Wed Apr 27
This is the file you need for Lab Twelve:
-rw-r--r--  1 dgerman faculty 71328 Apr 14  2003 /l/www/classes/a348/software/mm.mysql-2.0.2-bin.jar
Setting up a small table and the servlet posted on Tue Apr 18 would be enough for Lab Twelve.

Tue Apr 26
Temporary access to the MySQL driver for Lab Twelve (standalone application):
java -classpath ./mm.mysql-2.0.2-bin.jar:$CLASSPATH Three France
(We assume that the .jar file is in the folder where we run this.)

Wed-Mon Apr 20-25
Chris Hardy asked about storing arrays in sessions.

Here's a servlet, does it help in any way (what exactly does it do?)

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class One extends HttpServlet {

    int[] cards = {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
                   8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14} ;
    String cardS = "";

    public void doGet(HttpServletRequest request,
		      HttpServletResponse response)
	throws ServletException,
	       IOException {

        String message = request.getParameter("message");
	response.setContentType("text/html");
	PrintWriter out = response.getWriter();
        if (message == null) {

            cardS  = "";

            for (int i = 0; i < 100; i++) {
                int a = (int) (Math.random() * cards.length);
                int b = (int) (Math.random() * cards.length);
                int temp = cards[a];
                cards[a] = cards[b];
                cards[b] = temp;
            }

            for (int i = 0; i < cards.length; i++)
                cardS += cards[i] + " ";
        } else {

            cardS = request.getParameter("cards");
            StringTokenizer st = new StringTokenizer(cardS);

            if (st.countTokens() > 0) {

                String t1 = st.nextToken(), t2= st.nextToken();

                message = "( " + t1 + ", " + t2 + ")";

                cardS = "";
                while (st.hasMoreTokens()) {
                    cardS = cardS + " " + st.nextToken();
                }

            } else {

                cardS  = "";

                for (int i = 0; i < 100; i++) {
                    int a = (int) (Math.random() * cards.length);
                    int b = (int) (Math.random() * cards.length);
                    int temp = cards[a];
                    cards[a] = cards[b];
                    cards[b] = temp;
                }

                for (int i = 0; i < cards.length; i++)
                    cardS += cards[i] + " ";

            }

        }

	out.println(
"<form method=GET>" +
message + "<p> " + cardS +
"  <input type=\"hidden\" name=\"message\" value=\"welcome\"> " +
"  <input type=\"hidden\" name=\"cards\" value=\"" + cardS + "\">" +
"  <p> <input type=\"submit\" value=\"Proceed\">" +
"</form>"

        );

    }
}

Mon-Tue Apr 18-19
The two programs developed Tue in class:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class Three extends HttpServlet {
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws ServletException,
               IOException {
        response.setContentType("text/html");
        String place = request.getParameter("place");
        PrintWriter out = response.getWriter();
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
        } catch (Exception e) {
            out.println("Can't load JDBC Driver. Make sure classpath is correct.");
        }
        String url = "jdbc:mysql://localhost/a348",
            username = "a348",
            password = "a348AG";
        Connection connection;
        try {
            connection = DriverManager.getConnection(url, username, password);
            Statement statement = connection.createStatement();
            ResultSet result;
            out.println("Querying database...");
            result = statement.executeQuery(
              " select name, age from djcash_person    " +
              "        where lives_in = '" + place + "'        "
            );
            while (result.next()) {
                out.println(" " + result.getString(1) +
                                   ", " + result.getString(2));
            }
            statement.close();
            connection.close();
        } catch (SQLException e) {
            out.println("An SQLException occurred: " + e.getMessage());
        } catch (Exception e) {
            out.println("Exception: " + e);
        }
    }
}
The above program based on Lab Twelve.

The one below is starting the Midterm problem:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class One extends HttpServlet {

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
              throws ServletException, IOException {

    response.setContentType("text/html");
    HttpSession session = request.getSession();
    String message = (String) session.getAttribute("message");
    if (message == null) {
      session.setAttribute("message", "Welcome");
      session.setAttribute("one", "___");
      session.setAttribute("two", "___");
      session.setAttribute("thr", "___");
      session.setAttribute("sum", "" + ((int)(Math.random() * 16) + 3));
    } else {
      String where = request.getParameter("where");
      if (where == null) {

      } else {
        if (where.equals("one")) {
          int sum = Integer.parseInt((String)session.getAttribute("sum"));
          session.setAttribute("one", "" + sum);
        } else if (where.equals("two")) {
          int sum = Integer.parseInt((String)session.getAttribute("sum"));
          session.setAttribute("two", "" + sum);
        } else if (where.equals("thr")) {
          int sum = Integer.parseInt((String)session.getAttribute("sum"));
          session.setAttribute("thr", "" + sum);
        } else {

        }
        session.setAttribute("sum", "" + ((int)(Math.random() * 16) + 3));
      }
    }
    PrintWriter out = response.getWriter();

    out.println("Hello.");
    String me = request.getContextPath() + request.getServletPath();
    out.println(
      "<form method=GET action=" + me + ">" +

      "</form>"
    );

  }

}

Mon-Sun Apr 11-17
Here are the necessary steps for setting up the web chat app:
  1. Create a context under $CATALINA_HOME/webapps
  2. The context has this structure:
         ./WEB-INF/classes
                  /lib
                  /web.xml
  3. Place all your .html files in the root of the context.
  4. Place ChatApplet.java and HttpMessage.java in the root of the context.
  5. Place Chat.java and ChatServlet.java in ./WEB-INF/classes
  6. Prepare a web.xml that describes the two servlets:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app>
    
        <servlet>
            <servlet-name>Chat</servlet-name>
            <servlet-class>Chat</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>Chat</servlet-name>
            <url-pattern>/servlet/Chat</url-pattern>
        </servlet-mapping>
    
        <servlet>
            <servlet-name>ChatServlet</servlet-name>
            <servlet-class>ChatServlet</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>ChatServlet</servlet-name>
            <url-pattern>/servlet/ChatServlet</url-pattern>
        </servlet-mapping>
    
    </web-app>
  7. Update ChatApplet (port, context) and compile it.
  8. Compile HttpMessage.java as well.
  9. Update Chat.java (port, context) and compile it.
  10. Compile ChatServlet.java as well.
  11. Bring the server down. Start it up. Connect from a clean browser.
  12. Remember that we went over all these in class, on Thu, 4/14.

Sat-Sun Apr 9-10

Here's code developed with Daniel Helton during the Friday morning lab.

The code is the session-based version of the program developed by Adam on Thu.

First the servlet:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Two extends HttpServlet {

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
              throws ServletException, IOException {
        HttpSession session = request.getSession();
        String message = (String) session.getAttribute("message");
        String you = request.getContextPath() + request.getServletPath();
        PrintWriter out = response.getWriter();
        // Use "out" to send content to browser
        response.setContentType("text/html");
        if(message == null) {
          message = "1";
          out.println(message);
        }
        else {
          message = "" + (Integer.parseInt(message) + 1);
          out.println(message);
        }

        session.setAttribute("message",message);

        out.println(
          "<html>"+
          "<head><title>Homework 6</title></head>"+
          "<body>"+
          "<form method=\"get\" action = \""+you+"\">"+
          "<input type= \"submit\" value= \"proceed\">"+
          "</form>"+
          "</body>"+
          "</html>"
        );

  }

}
And here's the conversion to JSP:
<%
        String message = (String) session.getAttribute("message");
        String you = request.getContextPath() + request.getServletPath();

        if(message == null) {
          message = "1";
          out.println(message);
        } else {
          message = "" + (Integer.parseInt(message) + 1);
          out.println(message);
        }

        session.setAttribute("message",message);
%>
        <html>
          <head><title>Homework 6</title></head>
          <body>
            <form method="get" action = "<%=you%>">
              <input type= "submit" value= "proceed">
            </form>
          </body>
        </html>
In both cases printing should be done later.

It should be done in the HTML at the bottom, but it would work as it is, too.

Thu-Fri Apr 7-8
Code developed with Adam in class on Thu night:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class One extends HttpServlet {

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
              throws ServletException, IOException {
        String message = request.getParameter("message");
        String you = request.getContextPath() + request.getServletPath();
        PrintWriter out = response.getWriter();
        // Use "out" to send content to browser
        response.setContentType("text/html");
        if(message == null) {
          message = "1";
          out.println(message);
        }
        else {
          message = "" + (Integer.parseInt(message) + 1);
          out.println(message);
        }


        out.println(
          "<html>"+
          "<head><title>Homework 6</title></head>"+
          "<body>"+
          "<form method=\"get\" action = \""+you+"\">"+

          "<input type=\"hidden\" name= \"message\" value= \""+message+"\">"+
          "<input type= \"submit\" value= \"proceed\">"+
          "</form>"+
          "</body>"+
          "</html>"
        );

  }

}
And the JSP:
<%
        String message = request.getParameter("message");

        String you = request.getContextPath() + request.getServletPath();

        if(message == null) {
          message = "1";
        } else {
          message = "" + (Integer.parseInt(message) + 1);
        }
 %>

<html>
  <head><title>Homework 6</title></head>
  <body>
    <form method="get" action="<%=you%>">
      The counter is: <%=message%> <p>
      <input type="hidden" name="message" value="<%=message%>">
      <input type="submit" value="proceed">
    </form>
  </body>
</html>

Wed Apr 6
Thanks to
Adam Justice
for sharing his web.xml with us:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <servlet>
        <servlet-name>One</servlet-name>
        <servlet-class>One</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>One</servlet-name>
        <url-pattern>/servlet/One</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Fv2_3</servlet-name>
        <servlet-class>Two</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Fv2_3</servlet-name>
        <url-pattern>/servlet/Fancy</url-pattern>
    </servlet-mapping>


</web-app>

Tue Apr 5
Date: Tue, 5 Apr 2005 12:40:59 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A348/A548 Spr. 2005 Distribution List <dgerman@indiana.edu>
Subject: quick info/confirmation needed

Dear A348/A548 Friends,

If you are in any way affiliated with the Two Wheel Philantrophy Project
(the Ride to Provide event) please send me a note with a brief note on the
type of tasks you're (or have been, or will be) responsible for.

I need this information for two reasons:

a) an acknowledgment page on the web site, and

b) you need to be protected by a legal agreement that Student Legal
Services is drafting for us (basic legal boilerplate, to be sure)

So please send me your name and involvment in the project soon so we can
get both of these done quickly. Many thanks and let me know.

... Adrian

Mon Apr 4
About the projects and the RTP/TWP roster.

Wed-Sun Mar 30-Apr  3
A summary of Tomcat installation steps:

  1. Get the file jakarta-tomcat-5.0.27.tar.gz from /l/www/classes/a348/software.
  2. Place it in ~/tomcat then use gunzip and tar xvf to extract the archive.
  3. Delete the archive, then move into the folder that was created.
  4. Place an updated copy of server.xml in the conf folder of the installation.
  5. Here's the address to your new server.xml file: ~/tomcat/jakarta*/conf/server.xml.
  6. Use your ports instead of mine (in red) as listed on the students and servers page.
  7. Define three environment variables in ~/.login
          setenv JAVA_HOME   /l/jdk1.4
          setenv CATALINA_HOME /u/dgerman/tomcat/jakarta-tomcat-5.0.27
          setenv CLASSPATH   .:$CATALINA_HOME/common/lib/servlet-api.jar
  8. Log out and log back in (or use source ~/.login).
  9. Start your server: $CATALINA_HOME/bin/startup.sh and check it on-line.

Mon-Tue Mar 28-29

Here's some code worked out with Chris Hardy, for Homework Five:
<html>
  <head><title>smdfhsda</title></head>
  <script>
    function uh(what) {
      var num = Math.round((Math.random() * 10));
      document.getElementById(what).innerHTML = "";       
      what = what + "_v";
      document.getElementById(what).innerHTML = num;
    }
  </script>
  <body>
    <form>
      <table>
      <tr><td> <span id="one"> <input type="radio" onClick=uh("one")> </span>
          <td> <span id="one_v"> ___ </span>
      <tr><td> <span id="two"> <input type="radio" onClick=uh("two")> </span>
          <td> <span id="two_v"> ___ </span>
      <tr><td> <span id="thr"> <input type="radio" onClick=uh("thr")> </span>
          <td> <span id="thr_v"> ___ </span>
      <tr><td> <span id="fou"> <input type="radio" onClick=uh("fou")> </span>
          <td> <span id="fou_v"> ___ </span>
   </form>
  </body>
</html>

A different approach to this would be:

<html>
  <head><title>smdfhsda</title></head>
  <script>
    function uh() {
       alert(document.forms[0].what[0].value);
       alert(document.forms[0].what[0].checked);
       alert(document.forms[0].what[1].value);
       alert(document.forms[0].what[1].checked);
       alert(document.forms[0].what[2].value);
       alert(document.forms[0].what[2].checked);
       alert(document.forms[0].what[3].value);
       alert(document.forms[0].what[3].checked);
    }
  </script>
  <body>
    <form>
      <table>
        <tr><td> <span id="one"> <input type="radio" name="what" value="1"> </span>
            <td> <span id="one_v"> ___ </span>
        <tr><td> <span id="two"> <input type="radio" name="what" value="2"> </span>
            <td> <span id="two_v"> ___ </span>
        <tr><td> <span id="thr"> <input type="radio" name="what" value="3"> </span>
            <td> <span id="thr_v"> ___ </span>
        <tr><td> <span id="fou"> <input type="radio" name="what" value="4"> </span>
            <td> <span id="fou_v"> ___ </span>
      </table> <p>
      <input type="button" value="P{roceed" onClick="uh()">
   </form>
  </body>
</html>
Combining the two we get (and this idea entirely, totally belongs to Chris)
<html>
  <head><title>smdfhsda</title></head>
  <body>
    <form>
      <table>
        <tr><td> <span id="one"> <input type="radio" name="uh" onClick="val=1;"> </span>
            <td> <span id="one_v"> ___ </span>
        <tr><td> <span id="two"> <input type="radio" name="uh" onClick="val=2;"> </span>
            <td> <span id="two_v"> ___ </span>
        <tr><td> <span id="thr"> <input type="radio" name="uh" onClick="val=3;"> </span>
            <td> <span id="thr_v"> ___ </span>
        <tr><td> <span id="fou"> <input type="radio" name="uh" onClick="val=4;"> </span>
            <td> <span id="fou_v"> ___ </span>
      </table> <p>
      <input type="button" value="P{roceed" onClick="alert(val);">
   </form>
  </body>
</html>

Thu-Sun Mar 24-27
Our approach remains unchanged:

Two programs discussed with Jun Omori in lab on Friday discuss retrieving/storing the state with Perl/DBI:

#!/usr/bin/perl

use CGI;
use DBI;
use MD5;

$DB = "DBI:mysql:a348";
$username = "a348";
$password = "a348AG";
$DB_TABLE = "dgerman_php_categories"; # just to show how general our approach is... 
$SECRET = "something secret";
$EXPIRE = 30 * 60 * 60 * 24; # one month

$q = new CGI;

$DBH = DBI->connect($DB, $username, $password, { PrintError => 0 }) ||
       die "Couldn't open database: ", $DBI::errstr;
my $state = &get_state($q->param('cat')); # retrieving (what state?) 
print $q->header, $q->start_html;
&show($state);
print $q->end_html;
$DBH->disconnect;

#--------------------------------(end of main program)------

sub get_state {
  my $id = shift;
  my $query = "SELECT * FROM $DB_TABLE WHERE catid = '$id'";
  my $sth = $DBH->prepare($query) || die "Prepare: ", $DBH->errstr;
  $sth->execute || die "Execute: ", $sth->errstr;
  my $state = $sth->fetchrow_hashref;
  $sth->finish;
  return $state;
}

sub show {
  my ($state) = @_; # simply a row in the table 
  print qq{
    <table>
      <tr> <td> Category ID <td> Category Name
      <tr> <td> $state->{catid} <td> $state->{catname}
    </table>
  }
}
This first program clarifies what get_state() actually does, and how general the procedure really is.

The second program focuses on how we store the (updated) state:

#!/usr/bin/perl

use CGI;
use DBI;
use MD5;
  
$DB = "DBI:mysql:a348";
$username = "a348";
$password = "a348AG";
$DB_TABLE = "dgerman_php_categories";
$SECRET = "something secret";
$EXPIRE = 30 * 60 * 60 * 24; # one month

$q = new CGI;
print $q->header, $q->start_html;
  
$DBH = DBI->connect($DB, $username, $password, { PrintError => 0 }) ||
       die "Couldn't open database: ", $DBI::errstr;
my $state = &get_state($q->param('cat')); # again, it's based on the key in the table 
    
$state->{catname} .= "."; # this is how we update the state (demo purposes)  
&save_state($state); # and we save it here 

&show($state);  
print $q->end_html;
$DBH->disconnect;

#--------------------------------(end of main program)------

sub get_state {
  my $id = shift;
  my $query = "SELECT * FROM $DB_TABLE WHERE catid = '$id'";
  my $sth = $DBH->prepare($query) || die "Prepare: ", $DBH->errstr;
  $sth->execute || die "Execute: ", $sth->errstr;
  my $state = $sth->fetchrow_hashref;
  $sth->finish;
  return $state;
}

sub show {   
  my ($state) = @_;
  print qq{
    <table>
      <tr> <td> Category ID <td> Category Name
      <tr> <td> $state->{catid} <td> $state->{catname}
    </table>
  }
}

sub save_state { # just update a row in a table 
  my ($state) = @_;
  my $sth = $DBH->prepare(<<END) || die "Prepare: ", $DBH->errstr;
UPDATE $DB_TABLE
  SET catname = ?
  WHERE catid = '$state->{catid}'
END
  $sth->execute($state->{catname}) || die "Execute: ", $DBH->errstr;
  $sth->finish;
} 

Wed Mar 23
Those interested in the internship should contact Zach Posner at: <zach@cultureu.org>

Tue Mar 22
Here's a project possibility if you're still pondering what to choose:
On Fri, 4 Mar 2005, Zachary Posner wrote:

> Adrian,
>
>
>
> By way of introduction, my name is Zach Posner, and I have been working with
> a team of Indiana University faculty & students (I am an alumni) in creating
> and launching a not-for-profit organization called cultureU
> (www.cultureU.org <http://www.cultureu.org/> ).  The mission of the
> organization is to promote the artistic creations of students on and around
> college campuses around the world.  Since our launch in December, we have
> seen unbelievable traffic from IU, and now we are seeing word of mouth bring
> us new visitors every day, and we look forward to the near future when we
> make a formal effort to launch the site nationwide.
>
>
>
> The reason that I write you is that while in discussions with our Web
> Developer Mitch Greenfield about finding a few student interns, he suggested
> that you would be one of the best resources at Indiana University for
> identifying top quality candidates.  Specifically he mentioned that we are
> in desperate need for students who have a strong understanding of PHP. Any
> leads or superior students that you could recommend would be greatly
> appreciated.
>
>
>
> As to the work environment & experience for these students, Mitch can attest
> that we do our best to ensure that cultureU will be the best experience that
> any student could encounter while still at university.
>
>
>
> Kind regards,
>
>
> Zach
>
>

Mon Mar 21
Welcome back, more announcements will be made tomorrow.

Sat-Sun Mar 12-20
Happy Spring Break to everybody!

Thu-Fri Mar 10-11
Labs are optional this week.

Help will be given with the homework to those present.

Wed-Thu Mar 9-10
Here's some code we need for Lab Eight:

<?
   function get_book_cats($isbn) {

       $conn = db_connect(); 

       $query = "select dgerman_php_catboo.catid, catname 
                 from dgerman_php_categories, dgerman_php_catboo 
                 where '$isbn' = dgerman_php_catboo.isbn and
                       dgerman_php_categories.catid = dgerman_php_catboo.catid"; 

       $result = @mysql_query($query); 


       if (! $result) return false;



       $num_cats = @mysql_num_rows($result); 
       if ($num_cats == 0) return false; 



              $cat_array = array(); 

              for (
                   $count = 0; 
                   $row = @mysql_fetch_array($result); 
                   $count++
                  ) 
                $cat_array[$count] = $row; 

       if (! is_array($cat_array)) {
                     echo "No categories currently available. <br>"; 
              }



              foreach ($cat_array as $row) {

                     $url = "show_cat.php?catid=".($row["catid"]); 
                     $title = $row["catname"]; 



                     do_html_url($url, $title); 

              }


   } 
 ?>

Tue Mar 8
Here's the code discussed in class last night (notice the change?)

<? 
   
if (! $message) {
     
$message "Welcome."
     
$one "empty"
     
$two "empty"
     
$thr "empty"
     
$fou "empty"
     
$fiv "empty"
     
$six "empty"
     
$state "one=$one&two=$two&thr=$thr&fou=$fou&fiv=$fiv&six=$six&message=$message";
   } else { 
     
// echo "I know you.";

     
if ($coin == "one"$one "full"
     if (
$coin == "two"$two "full"
     if (
$coin == "thr"$thr "full"
     if (
$coin == "fou"$fou "full"
     if (
$coin == "fiv"$fiv "full"
     if (
$coin == "six"$six "full"

     
$state "one=$one&two=$two&thr=$thr&fou=$fou&fiv=$fiv&six=$six&message=$message";
   } 
  
  
?>

<table>
<tr><td>1. <td> <a href="<? echo "$PHP_SELF?coin=one&$state" ?>"><?=$one?></a>
<tr><td>2. <td> <a href="<? echo "$PHP_SELF?coin=two&$state" ?>"><?=$two?></a>
<tr><td>3. <td> <a href="<? echo "$PHP_SELF?coin=thr&$state" ?>"><?=$thr?></a>
<tr><td>4. <td>
<? if ($fou == "full") { ?>
  full
<? } else { ?> 
<a href="<? echo "$PHP_SELF?coin=fou&$state" ?>"><?=$fou?></a>
<? ?>
<tr><td>5. <td> <a href="<? echo "$PHP_SELF?coin=fiv&$state" ?>"><?=$fiv?></a>
<tr><td>6. <td> <a href="<? echo "$PHP_SELF?coin=six&$state" ?>"><?=$six?></a>
</table>

<p> Click here to <a href="<? echo "$PHP_SELF?one=empty&two=empty&thr=empty&fou=empty&fiv=empty&six=empty&message=Welcome"?>">reset</a>



Mon Mar 7
List of due dates for everything to the end of the semester posted.

Homework Assignments 5-7 posted, announcements for 3-4 updated.

Aaron's notes on the registration system have been updated here.

Fri-Sun Mar 4-6
Here's a script that might help you with the exam:
<? 
   
if (! $message) {
     
$message "Welcome."
     
$one "empty"
     
$two "empty"
     
$thr "empty"
     
$fou "empty"
     
$fiv "empty"
     
$six "empty"
     
$state "one=$one&two=$two&thr=$thr&fou=$fou&fiv=$fiv&six=$six&message=$message";
   } else { 
     
// echo "I know you.";

     
if ($coin == "one"$one "full"
     if (
$coin == "two"$two "full"
     if (
$coin == "thr"$thr "full"
     if (
$coin == "fou"$fou "full"
     if (
$coin == "fiv"$fiv "full"
     if (
$coin == "six"$six "full"

     
$state "one=$one&two=$two&thr=$thr&fou=$fou&fiv=$fiv&six=$six&message=$message";
   } 
  
  
?>

<table>
<tr><td>1. <td> <a href="<? echo "$PHP_SELF?coin=one&$state" ?>"><?=$one?></a>
<tr><td>2. <td> <a href="<? echo "$PHP_SELF?coin=two&$state" ?>"><?=$two?></a>
<tr><td>3. <td> <a href="<? echo "$PHP_SELF?coin=thr&$state" ?>"><?=$thr?></a>
<tr><td>4. <td> <a href="<? echo "$PHP_SELF?coin=fou&$state" ?>"><?=$fou?></a>
<tr><td>5. <td> <a href="<? echo "$PHP_SELF?coin=fiv&$state" ?>"><?=$fiv?></a>
<tr><td>6. <td> <a href="<? echo "$PHP_SELF?coin=six&$state" ?>"><?=$six?></a>
</table>

<p> Click here to <a href="<? echo "$PHP_SELF?one=empty&two=empty&thr=empty&fou=empty&fiv=empty&six=empty&message=Welcome"?>">reset</a>




Thu Mar 3
Seven stages to getting Homework Three and Four done:

  1. stage one
  2. stage two
  3. stage three
  4. stage four
  5. stage five
  6. stage six
  7. stage seven

Wed Mar 2
New set of scripts for 2WP/R2P project will be explained in class tomorrow.

Website will be updated tonight with lots of info about the rest of the semester (see below).

Homework Assignments Lab Assignments
1 Basic Website 1 Unix archive etc.
2 Switchboard in CGI/Perl or
One Midterm Implementation or
One Project Stage
2 Basic CGI scripts
3 Protected folder
3 Database Setup for 2WP/R2P or
Another Implementation of Midterm Exam or
Another Stage of the Project
4 GET vs POST (HTTP)
5 MySQL and RDBMSs
4 PHP Scripts for 2WP/R2P or
Another Midterm Exam Implementation or
Another Stage of the Project
6 DBI based CGI sessions
7 Midterm Practice
5 Exam Problem in Javascript 8 PHP shopping cart
6 Exam Problem in Java Servlets
(with sessions and without sessions)
9 Javascript shopping cart
10 Tomcat installation
7 Exam Problem in Java Server Pages
(with and without sessions)
11 Web chat (Servlets/applets)
12 Discussion forum (JDBC/XSLT)

Mon-Tue Feb 28- Mar 1
Here's the prototype for your Midterm Exam.

A complete description will be posted by the time of the lecture, Tue.

Sat-Sun Feb 26-27

Read Aaron's account of the 02/26 project meeting to get all the details!

Homework Three and Four start-up posted (serves as intro to the R2P/2WP project scripts).

More practice problems to be posted soon.

The message of Friday night is below.

Date: Fri, 25 Feb 2005 21:07:09 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A348/A548 Spr. 2005 Distr. List <dgerman@indiana.edu>
Subject: Midterm Exam Update (A348/A548 Spring 2005)


Dear A348/A548 Friends,

The midterm exam is on Tuesday. It is a take home exam. You come and pick
up a problem from me and we discuss it in class. You then work on it, and
turn it in (post it on your website in four implementations) by Tue Mar 8
and Mon-Thu of the week before the break we should have 10-15' individual
appointments in which the exam(s) as a whole would be turned in one on one. 

So that would take off some of the pressure and would improve my grading,
as well. We'd use both lectures next week (and the lab,) to help you with
the exam. I think things would go much more smoothly this way.

If you need help or have any questions please let me know.

... Adrian

Fri Feb 25
Check these entries in your php.ini:
; to possible security problems, if the code is not very well thought of.
register_globals = On

; variable in order to use PHP's session functions.
session.save_path = /u/dgerman/apache/apache_1.3.26/phpsessions

Thu Feb 24
Help with Homework Three (last semester).

A link to Fall 2002 notes, and the ClassPak from that time.

Here's the code we developed in class on Tue:

<? session_start(); 

   if (
$message && !$reset) { // no new user

     
if ($age == $ageCopy) { 

       if (
$n1 $n2 == $answer) {
        
$message "Good answer"
        
$g $g 1
       } else {
        
$message "No way."
       }
       
$t $t 1;
       
$message .= " Now your score is: " $g " out of " $t

       
$n1 rand(0100); 
       
$n2 rand(0100); 

       
$age += 1

     } else {
       
$message "I am sorry, you can't reload."
       
$message .= "<p>Your score is still: " $g " out of " $t

     } 

   } else { 
// no state, new user, initialize state

     
session_register("g"); 
     
session_register("t"); 
     
session_register("n1"); 
     
session_register("n2"); 
     
session_register("message"); 

     
session_register("age"); 
     
$age 1

     
$g 0
     
$t 0
     
$message "Welcome, your score is: " $g " out of " $t;
     
$n1 rand(0100); 
     
$n2 rand(0100); 
   } 
 
?> 

<form>
  <?=$message?> <p>
  What is <?=$n1?> + <?=$n2?>? <input type="text" name="answer" size=4> <p>
  <input type="hidden" name="ageCopy" value="<?=$age?>">
  Click to <input type="submit" value="Proceed">
  <p> Click here to <a href="<?=$SCRIPT_NAME?>">reset</a>.
  <p> Click here to <input type="submit" name="reset" value="Reset">
</form>

Wed Feb 23
An older midterm.

And another one.

And another one.

Tue-Wed Feb 22-23
Schedule script for individual appointments.

Prototypes for exam preparation (and Homework 2, 3, 4 options):

Mon Feb 21
Additional links for exam preparation:

Fri-Sun Feb 18-20
Here are the programs developed in class Tue-Thu.

First the one that keeps state on the client side:

<?
  
if ($message && !$reset) {

    if (
$n1 $n2 == $answer) {
     
$message "Good answer"
     
$g $g 1
    } else {
     
$message "No way."
    }
    
$t $t 1;
    
$message .= " Now your score is: " $g " out of " $t
    
$n1 rand(0100); 
    
$n2 rand(0100); 

  } else { 
    
$g 0
    
$t 0
    
$message "Welcome, your score is: " $g " out of " $t;
    
$n1 rand(0100); 
    
$n2 rand(0100); 
  } 
 
?> 

<form>
  <?=$message?> <p>
  What is <?=$n1?> + <?=$n2?>? <input type="text" name="answer" size=4> <p>
  <input type="hidden" name="n1" value="<?=$n1?>">
  <input type="hidden" name="n2" value="<?=$n2?>">
  <input type="hidden" name="g" value="<?=$g?>">
  <input type="hidden" name="t" value="<?=$t?>">
  <input type="hidden" name="message" value="<?=$message?>">
  Click to <input type="submit" value="Proceed">
  <p> Click here to <a href="<?=$SCRIPT_NAME?>">reset</a>.
  <p> Click here to <input type="submit" name="reset" value="Reset">
</form>
Here's the second program (state on the server side):
<? session_start(); 

   if (
$message && !$reset) {

     if (
$n1 $n2 == $answer) {
      
$message "Good answer"
      
$g $g 1
     } else {
      
$message "No way."
     }
     
$t $t 1;
     
$message .= " Now your score is: " $g " out of " $t
     
$n1 rand(0100); 
     
$n2 rand(0100); 

   } else { 
// no state, new user, initialize state
     
session_register("g"); 
     
session_register("t"); 
     
session_register("n1"); 
     
session_register("n2"); 
     
session_register("message"); 
     
$g 0
     
$t 0
     
$message "Welcome, your score is: " $g " out of " $t;
     
$n1 rand(0100); 
     
$n2 rand(0100); 
   } 
 
?> 

<form>
  <?=$message?> <p>
  What is <?=$n1?> + <?=$n2?>? <input type="text" name="answer" size=4> <p>
  Click to <input type="submit" value="Proceed">
  <p> Click here to <a href="<?=$SCRIPT_NAME?>">reset</a>.
  <p> Click here to <input type="submit" name="reset" value="Reset">
</form>

Fri-Thu Feb 12-17
Lecture notes updated (the links point now in the past).

Grading in progress.

Here are some important links to be used this week in class:

Wed-Thu Feb 10-11
Here's a short description of why the current directory should not be in the path:
THE PATH VARIABLE

PATH is an environment variable that points to a list of directories, which are searched when a file is requested by a process. The order of that search is indicated by the sequence of the listed directories in the PATH name. This variable is established at user logon and is set up in the users .profile of .login file. If a user places the current directory as the first entry in PATH, then programs in the current directory will be run first. Programs in other directories with the same name will be ignored. Although file and directory access is made easier with a PATH variable set up this way, it may expose the user to pre-existing Trojan horses. To illustrate this, assume that a Trojan horse, similar to the cat utility, contains an instruction that imparts access privileges to a perpetrator. The fake cat is placed in a public directory /usr/his where a user often works. Now if the user has a PATH variable with the current directory first, and he enters the cat command while in /usr/his, the fake cat in /usr/his would be executed but not the system cat located in /bin. In order to prevent this kind of system violation, the PATH variable must be correctly set. First, if at all possible, exclude the current directory as the first entry in the PATH variable and type the full path name when invoking Unix system commands. This enhances file security, but is more cumbersome to work with. Second, if the working directory must be included in the PATH variable, then it should always be listed last. In this way, utilities like vi, cat, su and ls will be executed first from systems directories like /bin and /usr/bin before searching the user's working directory.

(From http://www.secinf.net/unix_security/Unix_System_Security_Issues.html).

Thu-Tue Feb 3-9
Mark Hursh has set up a draft web site for Two Wheel Philantropy Ride to Provide.

Tue-Wed Feb 2
Here's how your Homework Two program should behave.

Homework Two will be to create a simple switchboard.

Homework Three will be to connect it to a database (of usernames and passwords).

Both will be discussed in class on Thu, when we will also install PHP.

Here's the program developed in class Tuesday:

#!/usr/bin/perl

use CGI; 

$q = new CGI; # readParse happens 

print $q->header; 
print $q->start_html; 

if (! $q->param('message')) {

  $message = "Welcome"; 
  $good = 0; 
  $total = 0; 
  $n1 = int(rand(100) - 50); 
  $n2 = int(rand(100) - 50); 

} else {

  $answer = $q->param('userInput'); 
  if ($answer == $q->param(n1) + $q->param(n2)) {
    $good = $q->param('good') + 1; 
  } else {
    $good = $q->param('good'); 
  } 
  $total = $q->param('total') + 1; 
  $n1 = int(rand(100) - 50); 
  $n2 = int(rand(100) - 50); 
  $message = "Your score is: " . $good . "/" . $total; 

}

print $q->start_form, qq{
  $message <p> 
  What is $n1 + $n2 = <input type="text" name="userInput"> 
  <input type="hidden" name="message" value="$message"> 
  <input type="hidden" name="n1" value="$n1"> 
  <input type="hidden" name="n2" value="$n2"> 
  <input type="hidden" name="good" value="$good"> 
  <input type="hidden" name="total" value="$total"> 

}, $q->end_form; 

print $q->end_html; 

Sat-Mon Jan 29-31
This week we stretch a bit ahead and install PHP.

We'll get a better perspective on CGI/Perl, CGI.pm and PHP for Lab Four (HTTP).

Here's a link to the R2P project site to get started.

Logo above still designed by
Mark Hursh

Fri Jan 28
Proposed logo developed by Mark Hursh after Ryan's presentation last night:

Here's a picture of Mark as well.

Wed-Thu Jan 26-27
Simple quiz program that keeps state and uses all we learned so far:
#!/usr/bin/perl

print qq{Content-type: text/html\n\n}; 
print qq{<html><head><title>Quiz</title></head><body>}; 
# state: $message, $good, $total, $n1, $n2 
&readParse; 
foreach $k (keys %entry) {
  print $k, " --> ", $entry{$k}, "\n<p>"; 
}

if ($entry{message} eq "") { 
  $message = "Welcome to the game."; 
  $n1 = int(rand(100)) - 50; 
  $n2 = int(rand(100)) - 50; 
  $good = 0; 
  $total = 0; 
} else {
  $good = $entry{good}; 
  $total = $entry{total}; 
  if ($entry{answer} == $entry{n1} + $entry{n2}) {
    $good += 1; 
  } else {

  } 
  $total += 1; 
  $message = "Your score so far is: $good out of $total.";   
  $n1 = int(rand(100)) - 50; 
  $n2 = int(rand(100)) - 50; 

}

print qq{
  <form>
    $message <p> 
    What is $n1 + $n2? Answer: <input type="text" name="answer" size=5>
    <input type="hidden" name="n1" value="$n1">     
    <input type="hidden" name="n2" value="$n2">     
    <input type="hidden" name="message" value="$message">      
    <input type="hidden" name="good" value="$good">     
    <input type="hidden" name="total" value="$total">     

    <p> When finished please press <input type="submit" value="Proceed"> 
  </form>
}; 

print qq{</body></html>}; 

sub readParse{ 
  $input = $ENV{QUERY_STRING}; 
  @pairs = split(/&/, $input); 
  foreach $pair (@pairs) {
    ($a, $b) = split(/=/, $pair); 
    $entry{$a} = $b; 
  } 
}

Mon-Tue Jan 24-25
Here's the template we will try to establish today:

Sat-Sun Jan 22-23
Useful link for the course.

Here's the program we wrote in class on Thursday:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "<html><head><title>This is my program.</title></head><body>";

$input = $ENV{QUERY_STRING};  

@pairs = split(/&/, $input);

foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair);
  $form{$name} = $value;
}
      
foreach $key (keys %form) {
  print $key, " --> ", $form{$key}, "<p>";
}
    
$balance = $form{balance} + $form{amount};
  
print qq{

  <form method=GET action="/cgi-bin/01202005/one">

    Your balance currently is:

    <input type="text" name="balance" value="$balance"> <p>

    Please type an amount: <input type="text" name="amount" size=8> <p>

    Choose a function: <select name="operation">
      <option value="nothing"> Click me!
      <option value="deposit"> Deposit
      <option value="withdraw"> Withdraw
    </select>

    <p> <input type="submit" value="Go ahead!">

  </form>
};

print "</body></html>";

Lecture Notes Five and Six are really all about this program.

Thu Jan 20
The programs we wrote in class on Tuesday are in Lecture Notes Four, towards the end.

Here's the command prompt calculator:

#!/usr/bin/perl

$balance = 0; 
print "Your balance is: $balance\n"; 
print "Type> "; 
while ($line = <STDIN>) {
  chop($line); 
  ($fun, $arg) = split(/ /, $line, 2); 
  print "You want to $fun a value of $arg to the balance of $balance.\n";
  if ($fun =~ /^add/i) {
    $balance += $arg; 
  } elsif ($fun =~ /^sub/i) {
    $balance -= $arg; 
  } else {
    print "I am sorry I don't understand $fun.";
  } 
  print "The balance is now: ", $balance, "\n"; 
  print "Type> "; 
}
Here's the program that reports the time, as well the contents of hashtable %ENV:
#!/usr/bin/perl

print "Content-type: text/html\n\n"; 

$time = localtime; 

print "Hello! The time is now: $time"; 

foreach $key (keys %ENV) {
  print $key, " --> ", $ENV{$key}, "<br>"; 
}

Thu Jan 20
Lecture notes for next week posted.

Wed Jan 19
Class notes pages updated, more to follow soon.

Tue Jan 18
Remember that for Lab One you need to have permissions set like so:
chmod 711 ~
chmod 755 ~/public
chmod 644 ~/public/whoa.tar.gz

Fri-Mon Jan 14-17
Here's the script that checks your Lab One:
http://burrowww.cs.indiana.edu:13280/cgi-bin/check

Thu Jan 13
A348/A548 Message Board has been created.

Wed Jan 12
Gradebook created in OnCourse, requests for additional accounts sent.

Current list of students and assigned port numbers has been posted.

Tue Jan 11
A348 starts. First lecture in Lindley Hall 201D at 5:45pm.

Mon Jan 10
Spring semester of 2005 starts.

Here's a link to A348's entry on the Registrar's web site.


Updated by Adrian German for A348/A548