Second Summer 2004


Thu Aug 12
FINAL EXAM in class today.

Programs worked out in class yesterday:

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

public class One extends HttpServlet {
    public void doGet(HttpServletRequest request, 
		      HttpServletResponse response) 
	throws ServletException, 
	       IOException {

	response.setContentType("text/html"); 
	PrintWriter out = response.getWriter(); 

HttpSession session = request.getSession(); 
String message = (String) session.getAttribute("message"); 
String age = (String) session.getAttribute("age"); 
String balance = (String) session.getAttribute("balance"); 

if (message == null) {
  message = "Welcome to the game."; session.setAttribute("message", message); 
  age = "1"; session.setAttribute("age", age); 
  balance = "0"; session.setAttribute("balance", balance); 
} else {
  String arg = request.getParameter("arg"); 
  String fun = request.getParameter("fun"); 
  int argC = 0; 
  try {
    argC = Integer.parseInt(arg); 
  } catch (Exception e) { }
  int ageCopy = 0;  
  try {
    ageCopy = Integer.parseInt(request.getParameter("ageCopy")); 
  } catch (Exception e) { } 
  message = "The stamps don't match."; 
  if (Integer.parseInt(age) == ageCopy) { 
    if (fun != null && fun.equals("add")) {
      message = "OK, you deposited some money."; 
      balance = Integer.parseInt(balance) + argC + ""; 
    } else if (fun != null && fun.equals("sub")) {
      message = "Withdrawing " + argC + " from the bank."; 
      balance = Integer.parseInt(balance) - argC + "";   
    } else { 
      message = "You asked for something I don't understand."; 
    }    
    age = Integer.parseInt(age) + 1 + ""; 
  } 
  session.setAttribute("message", message); 
  session.setAttribute("age", age); 
  session.setAttribute("balance", balance);  
} 

	out.println( 
"<form>" + message + "<p>" + "Your balance is " + balance +
"<p>" + "The age of the expected transaction is: " + age + " <p>" + 
"<select name=\"fun\">" + 
"  <option value=\"non\"> Click me! " + 
"  <option value=\"add\"> Deposit  " + 
"  <option value=\"sub\"> Withdraw  " + 
"</select> <p> Please enter the amount " + 
"<input type=\"text\" name=\"arg\" size=\"8\"> <p> " +  
"<input type=\"hidden\" name=\"ageCopy\" value=\"" + age + "\"> <p> " +  
"When ready press <input type=\"submit\" value=\"Proceed\">" +  
"</form>"
        ); 
    }
}
Here's the second one, transformed from the first:
<%

String message = (String) session.getAttribute("message"); 
String age = (String) session.getAttribute("age"); 
String balance = (String) session.getAttribute("balance"); 

if (message == null) {
  message = "Welcome to the game."; session.setAttribute("message", message); 
  age = "1"; session.setAttribute("age", age); 
  balance = "0"; session.setAttribute("balance", balance); 
} else {
  String arg = request.getParameter("arg"); 
  String fun = request.getParameter("fun"); 
  int argC = 0; 
  try {
    argC = Integer.parseInt(arg); 
  } catch (Exception e) { }
  int ageCopy = 0;  
  try {
    ageCopy = Integer.parseInt(request.getParameter("ageCopy")); 
  } catch (Exception e) { } 
  message = "The stamps don't match."; 
  if (Integer.parseInt(age) == ageCopy) { 
    if (fun != null && fun.equals("add")) {
      message = "OK, you deposited some money."; 
      balance = Integer.parseInt(balance) + argC + ""; 
    } else if (fun != null && fun.equals("sub")) {
      message = "Withdrawing " + argC + " from the bank."; 
      balance = Integer.parseInt(balance) - argC + "";   
    } else { 
      message = "You asked for something I don't understand."; 
    }    
    age = Integer.parseInt(age) + 1 + ""; 
  } 
  session.setAttribute("message", message); 
  session.setAttribute("age", age); 
  session.setAttribute("balance", balance);  
} 
%> 

<form> <%=message%> <p> Your balance is <%= balance %> 
<p> The age of the expected transaction is: <%=age%> <p> 
<select name="fun"> 
  <option value="non"> Click me! 
  <option value="add"> Deposit  
  <option value="sub"> Withdraw  
</select> <p> Please enter the amount 
<input type="text" name="arg" size="8"> <p> 
<input type="hidden" name="ageCopy" value="<%=age%>"> <p> 
When ready press <input type="submit" value="Proceed">  
</form>
And the last one, that we solved first:
<% 
 String user = request.getParameter("user"); 
 String me = request.getContextPath() + request.getServletPath(); 
 %> 
<html>
  <head><title>My Portfolio on Aug 11, 2004</title></head>
  <body>
    <table border cellpadding=2>
      <tr> <td>
<% 
 if (user != null && user.equals("one")) { %>
   One  
<%
 } else { %>
   <a href="<%=me%>?user=one">One</a> 
<%
 }
 %> 
           <td> 
<% 
 if (user != null && user.equals("two")) { %>
   Two
<%
 } else { %>
   <a href="<%=me%>?user=two">Two</a> 
<%
 }
 %> 
           <td>
<% 
 if (user != null && user.equals("three")) { %>
   Thr
<%
 } else { %>
   <a href="<%=me%>?user=three">Thr</a> 
<%
 }
 %> 
           <td> 
<% 
 if (user != null && user.equals("four")) { %>
   Fou
<%
 } else { %>
   <a href="<%=me%>?user=four">Fou</a> 
<%
 }
 %> 
      <tr> <td colspan=4 align=center> 
<% 
 if (user == null) { %>
   <img src="http://www.cc.columbia.edu/low3.gif"> 
<%
 } else if (user.equals("one")) { %>
   <img src="http://www.cs.indiana.edu/dept/img/lh01.gif"> 
<%
 } else if (user.equals("two")) { %>
   <img src="http://www.cs.indiana.edu/dept/img/lh07.gif"> 
<%
 } else if (user.equals("three")) { %>
   <img src="http://www.cs.indiana.edu/dept/img/lh08.gif"> 
<%
 } else if (user.equals("four")) { %>
   <img src="http://www.cs.indiana.edu/dept/img/lh09.gif"> 
<%
 } else  { %>
   <img src="http://www.cc.columbia.edu/low3.gif"> 
<%
 } 
 %> 
      <tr> <td colspan=4 align=center> 

<% 
 if (user == null) { %>
   No picture selected. 
<%
 } else if (user.equals("one")) { %>
   First picture. 
<%
 } else if (user.equals("two")) { %>
   Second (no. 7) 
<%
 } else if (user.equals("three")) { %>
   Third (no. 8) 
<%
 } else if (user.equals("four")) { %>
   Fourth (no. 9) 
<%
 } else  { %>
   Invalid picture name (<%= user %>)  
<%
 } 
 %> 

    </table>
  </body>
</html> 

Wed Aug 11
Here are the two programs developed in class yesterday. First, the servlet:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Exam extends HttpServlet {
    public void doGet(HttpServletRequest request,
		      HttpServletResponse response) throws ServletException, IOException {
	response.setContentType("text/html");
	PrintWriter out = response.getWriter();
        HttpSession session = request.getSession(); 
        String message = (String)session.getAttribute("message"); 
        String one = (String)session.getAttribute("one"), 
               two = (String)session.getAttribute("two"), 
               balance = (String)session.getAttribute("balance"), 
               answer = "", bet = ""; 
        if (message == null) {
          one = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("one", one); 
          two = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("two", two); 
          balance = "5000"; session.setAttribute("balance", balance); 
          message = "Welcome to the game."; session.setAttribute("message", message); 
        } else {
          answer = request.getParameter("guess"); 
          bet = request.getParameter("bet"); 
          int sum = Integer.parseInt(one) + Integer.parseInt(two); 
          if (sum % 2 == 0 && answer.equals("eve") ||
              sum % 2 == 1 && answer.equals("odd")) { 
            balance =  Integer.parseInt(balance) + Integer.parseInt(bet) + ""; 
          } else {
            balance =  Integer.parseInt(balance) - Integer.parseInt(bet) + ""; 
          } 
          one = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("one", one); 
          two = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("two", two); 
          session.setAttribute("balance", balance); 
          message = "You are a new user no longer."; 
          session.setAttribute("message", message);

        }
	out.println("<form method=GET>" + message + 
          "Your balance is: " + balance + "<p>" + 
          "How is " + one + " + " + two + ", odd or even? <p>" + 
          "Please choose <select name=guess> " + 
          "   <option value=non> Click me! " +
          "   <option value=eve> Even " +
          "   <option value=odd> Odd " +
          "  </select> <p> ... and place your bet here: " + 
          "  <input type=text name=bet size=8> <p> Then press " + 
          " <input type=submit value=Proceed> when you're ready." + 
          "</form>"
        );
    }
}
This took us about 34 minutes. Then the conversion to JSP was done in 1/17 of that.

<%
        String message = (String)session.getAttribute("message"); 
        String one = (String)session.getAttribute("one"), 
               two = (String)session.getAttribute("two"), 
               balance = (String)session.getAttribute("balance"), 
               answer = "", bet = ""; 
        if (message == null) {
          one = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("one", one); 
          two = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("two", two); 
          balance = "5000"; session.setAttribute("balance", balance); 
          message = "Welcome to the game."; session.setAttribute("message", message); 
        } else {
          answer = request.getParameter("guess"); 
          bet = request.getParameter("bet"); 
          int sum = Integer.parseInt(one) + Integer.parseInt(two); 
          if (sum % 2 == 0 && answer.equals("eve") ||
              sum % 2 == 1 && answer.equals("odd")) { 
            balance =  Integer.parseInt(balance) + Integer.parseInt(bet) + ""; 
          } else {
            balance =  Integer.parseInt(balance) - Integer.parseInt(bet) + ""; 
          } 
          one = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("one", one); 
          two = (int)(Math.random() * 6 + 1) + ""; session.setAttribute("two", two); 
          session.setAttribute("balance", balance); 
          message = "You are a new user no longer."; 
          session.setAttribute("message", message);

        }
 %>

<form method=GET> <%=message%> 
Your balance is: <%=balance%> <p>
How is <%=one%> + <%=two%> odd or even? <p>
Please choose <select name=guess> 
   <option value=non> Click me! 
   <option value=eve> Even 
   <option value=odd> Odd 
  </select> <p> ... and place your bet here: 
  <input type=text name=bet size=8> <p> Then press  
 <input type=submit value=Proceed> when you're ready.
</form>
Here also is the function needed in Lab Assignment 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 Aug 10
Here's a servlet, what 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 Aug 9
Here's the message of Friday:
Date: Fri, 6 Aug 2004 16:07:08 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: Fulya Erdinc <ferdinc@cs.indiana.edu>, rallis@indiana.edu, 
    dcbeck@indiana.edu, jcoddens@indiana.edu, pdaccare@indiana.edu, 
    ddepersi@indiana.edu, ggordon@indiana.edu, brhiggin@indiana.edu, 
    schollan@indiana.edu, jcmiles@indiana.edu, fsharp@indiana.edu, 
    anmstewa@indiana.edu, puthuppu@indiana.edu, ninliu@indiana.edu, 
    mzhai@indiana.edu
Subject: A348 update

Please go to to

   http://burrowww.cs.indiana.edu:11400/cgi-bin/sum2004/schedule

and make and appointment for next week to discuss your final grades.

All assignments must be in by Tue 8am. Final exam is on Thu in class.

You need to come and take a 15 minutes test in addition to the take-home
final you're working on. The test is closed-book, and will last 15 mins.
Questions will be very general about the material covered in class this
semester (no code, just basic questions like these:

   What is Apache?
   What is CGI?
   What is the relationship between Perl and CGI?
   What is CGI.pm?
   What is PHP?
   What's the relationship between PHP and CGI.pm?
   What is Java?
   What is Javascript?
   What's the relationship between Javascript and Java?
   What is XML?
   What is HTML?
   What is DHTML?
   What is DOM?
   What is Tomcat?
   What's the relationship between Tomcat and the Apache web server?
   What is MySQL?
   What is the difference between SQL and MySQL?
   Can you access an RDBMS (what is that?) from CGI/Perl?
   Can you access an RDBMS from PHP? From Java?
   What are servlets?
   What are Java Server Pages?
   What is the relationship between Java servlets and JSPs?
   What are sessions?
   Describe the session mechanism in CGI/Perl, PHP and server-side Java.
   In how many ways can we keep state? What does it mean to keep state?
   Draw the flowchart for keeping state regardless of technology used.)

Please come. Please make appointments next week.

You can make more than one appointment. Make appointments early so I can
help you or give you the final grade early. If you are ready to take the
15 exam when you come for your appointment you can get your final grade
right then and there.

Please make an effort and schedule an appointment.

Then come so we can talk. I have seen half of you this week, but I also
have missed some and didn't see others at all. So I am looking forward to
this week's appointments. More information has been posted on the What's
New? page

   http://www.cs.indiana.edu/classes/a348-dger/sum2004/whatsnew.html

including the link to the appointments script:

   http://burrowww.cs.indiana.edu:11400/cgi-bin/sum2004/schedule

and some help with the last assignment.

Hope everybody is doing well. Please let us know if you need help.

... Adrian

Sat-Sun Aug 7-8
Please make appointments next week to discuss your final grades.

Also, thanks to Mengyu Zhai for suggesting that the following be posted:

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

public class One extends HttpServlet {

    public void doGet(HttpServletRequest req, 
                      HttpServletResponse res) 

        throws ServletException, 
               IOException {
        
        res.setContentType("text/html"); 
        PrintWriter out = res.getWriter(); 

        String one, two; 

        String what = req.getParameter("picture"); 

        if (what == null) {
            what = ""; 
        }

        if (what.equals("one")) { one = "One"; } else {
            one = "<a href=\"/examples/servlet/One?picture=one\">One</a>"; 
        } 

        if (what.equals("two")) { two = "Two"; } else {
            two = "<a href=\"/examples/servlet/One?picture=two\">Two</a>"; 
        } 

        out.println("<html><head><title>Mamma mia!</title></head><body bgcolor=\"white\">" + 
                    "<table border><tr><td>" + 

                    one + 

                    "</td><td>" + 

                    two +

                    "</td><td>Three</td><td>Four</td></tr>" + 
                    "<tr><td colspan=4 align=center>Picture</td></tr>" + 
                    "<tr><td colspan=4 align=center>Caption</td></tr>" + 
                    "</table></body></html>"); 
        
        

    }
Here now is the starting point for the calculator.

<html><head><title>My calculator</title></head><body>

<% Integer a = (Integer)session.getAttribute("acc");

   if (a == null) { a = new Integer(0); } 

   String argument = request.getParameter("arg"); 

   if (argument == null) { argument = "0"; }

   int conv; 

   try { 
     conv = Integer.parseInt(argument); 
   } catch(Exception e) { conv = 0; } 

   a = new Integer(a.intValue() + conv); 

   session.setAttribute("acc", a);

 %>

 <form>

 
   The accumulator is now: <%= a %> <p> 

   <input type="text" name="arg"> <p> 

 </form>

</body></html>
These (with care) should be of great help to you in working out Homework Assignments 6 and 7.

Fri Aug 6
Here's the program developed in class yesterday:
<html>
  <head><title>Example problem for the final</title>
  <script language="javascript">
    var one = Math.round(1 + Math.random() * 5);
    var two = Math.round(1 + Math.random() * 5);
    var balance = 5000;
    var message;
    function process() {
      var guess = document.one.sum.options[document.one.sum.selectedIndex].value;
      var bet = document.one.bet.value;
      // alert("You are betting " + bet +" on " + guess);
      if ( (guess == "eve" && (one + two) % 2 == 0) ||
           (guess == "odd" && (one + two) % 2 == 1)
         ) {
        balance = eval(balance) + eval(bet);
        message = "Good guess.";
      } else {
        balance -= bet;
        message = "Too bad.";
      }
      one = Math.round(1 + Math.random() * 5);
      two = Math.round(1 + Math.random() * 5);
      // alert(balance);

      document.getElementById("dice").innerHTML = "(" + one + ", " + two + ")";
      document.getElementById("balance").innerHTML = balance;
      document.getElementById("message").innerHTML = message;

    }
    function changeBalance() {
      balance += 1;
      document.getElementById("balance").innerHTML = balance;
    }
  </script>
  </head>
  <body bgcolor="white">
  <a href="javascript:alert('Howdy!')">Click here for a greeting</a>. <p>
  <a href="javascript:changeBalance()">Click here to change the balance</a>. <p>
  <form name="one">
  <span id="message"> Welcome to our game. </span> <p>
  The dice show <span id="dice"> </span>. <p>
  Your balance is <span id="balance"> </span>. <p>
  What is the sum: <select name="sum">
    <option value="non"> Click me!
    <option value="eve"> Even
    <option value="odd"> Odd
  </select> <p>
  How much do you want to bet: <input type="text" name="bet" size=6> <p>
  When ready please push: <input type="button" value="Proceed"
                                               onClick="process()"
                           >
  </form>
  <script language="javascript">
    document.getElementById("dice").innerHTML = "(" + one + ", " + two + ")";
    document.getElementById("balance").innerHTML = balance;
  </script>
  </body>
</html>

Thu Aug 5
A little help with HW3 queries.

Wed Aug 4
Here is the program developed in class today:
<html>
  <head><title>Example problem for the final</title>
  <script language="javascript">
    var one = Math.round(1 + Math.random() * 5);
    var two = Math.round(1 + Math.random() * 5);
    // alert("The dice is: " + one);
  </script>
  </head>
  <body bgcolor="white">
  <form>
  The dice show <span id="dice"> </span>. <p>
  Your balance is 5000. <p>
  What is the sum: <select name="sum">
    <option value="non"> Click me!
    <option value="eve"> Even
    <option value="odd"> Odd
  </select> <p>
  How much do you want to bet: <input type="text" name="bet" size=6> <p>
  When ready please push: <input type="button" value="Proceed"
                                               onClick="alert('No kidding.')" 
                           >
  </form>
  <script language="javascript">
    document.getElementById("dice").innerHTML = "(" + one + ", " + two + ")"; 
  </script>
  </body>
</html>
It will be completed tomorrow.

Here's the other program we used as a reference:

<html><head><title>First to 100</title>

  <script language="javascript">

    var acc = 0; // state
    var message = ""; // also part of state

    function calculate() {

      arg = document.forms[0].arg.value; // read input

      var oldAcc = acc; // so it would look like fibonacci in the end (for fun and better reporting)

      if (arg > 10 || arg < 1) { message = arg + " is not a legal value."; } else { // process the state

        acc += eval(arg);

        if (acc >= 100) { message = "Game ends. You win."; } else {

          var comp = Math.round(1 + Math.random() * 10);

          if (acc >= 100) { message = "Game ends. Computer wins." } else {

            acc += comp;

            message = "Game is under way.";

          }

        }

      } // end of process the state (we don't need to store (or retrieve it, for that matter))

      document.getElementById("acc").firstChild.nodeValue
        = oldAcc + " + " + arg + " + " + comp + " = " + acc + " (" + message + ") "; // print state

      document.forms[0].arg.value = ""; // get ready for new input
    }
  </script>
  </head><body bgcolor=white>

  <form>

    <table cellpadding=6>

    <tr> <td> The value of the game is currently <span id="acc"> 0 (zero). </span> </td> </tr>

    <tr> <td> Please enter a number (between 1-10): <input type="text" name="arg" size=4> </td> </tr>

    <tr> <td> When ready, please press <input type="button"
                                              value="Proceed"
                                              onClick="calculate()"
                                       >
         </td>
    </tr>

  </form>

  </body>
</html>
We'll discuss it in class tomorrow (again).

Tue Aug 3
We will be looking at Homework Three today.

Thanks to Ning and Gabe for their contributions:

Script started on Tue Aug 03 09:10:06 2004
burrowww.cs.indiana.edu% mysql -ua348 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11268 to server version: 4.0.18-standard

Type 'help;' or '\h' for help. Type '\c' to clear the buffer

mysql> use a348
Database changed
mysql> show tables like '%ninliu%HW%';
+------------------------------+
| Tables_in_a348 (%ninliu%HW%) |
+------------------------------+
| ninliu_HW3_enrollment        |
| ninliu_HW3_matches           |
| ninliu_HW3_participation     |
| ninliu_HW3_players           |
| ninliu_HW3_spectators        |
| ninliu_HW3_venues            |
+------------------------------+
6 rows in set (0.04 sec)

mysql> show tables like 'lbird%';
+-------------------------+
| Tables_in_a348 (lbird%) |
+-------------------------+
| lbird_board             |
| lbird_message           |
| lbird_newtable          |
| lbird_person            |
+-------------------------+
4 rows in set (0.04 sec)

mysql> describe ninliu_HW3_enrollment;
+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| matchID      | varchar(30)  | YES  |     | NULL    |       |
| tickets      | decimal(4,0) | YES  |     | NULL    |       |
| universityID | varchar(25)  | YES  |     | NULL    |       |
+--------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> create table lbird_HW3_enrollment select * from ninliu_HW3_enrollment;
Query OK, 22 rows affected (0.04 sec)
Records: 22  Duplicates: 0  Warnings: 0

mysql> show tables like 'lbird%';
+-------------------------+
| Tables_in_a348 (lbird%) |
+-------------------------+
| lbird_HW3_enrollment    |
| lbird_board             |
| lbird_message           |
| lbird_newtable          |
| lbird_person            |
+-------------------------+
5 rows in set (0.05 sec)

mysql> describe ninliu_HW3_enrollment; 
+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| matchID      | varchar(30)  | YES  |     | NULL    |       |
| tickets      | decimal(4,0) | YES  |     | NULL    |       |
| universityID | varchar(25)  | YES  |     | NULL    |       |
+--------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table lbird add key (matchID, universityID);
Query OK, 22 rows affected (0.07 sec)
Records: 22  Duplicates: 0  Warnings: 0

mysql> describe lbird_HW3_enrollment;
+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| matchID      | varchar(30)  | YES  | MUL | NULL    |       |
| tickets      | decimal(4,0) | YES  |     | NULL    |       |
| universityID | varchar(25)  | YES  |     | NULL    |       |
+--------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table lbird_HW3_enrollment add primary key (matchID, universityID); 
Query OK, 22 rows affected (0.07 sec)
Records: 22  Duplicates: 0  Warnings: 0

mysql> describe lbird_HW3_enrollment;
+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| matchID      | varchar(30)  |      | PRI |         |       |
| tickets      | decimal(4,0) | YES  |     | NULL    |       |
| universityID | varchar(25)  |      | PRI |         |       |
+--------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from lbird_HW3_enrollment;
+---------+---------+----------------+
| matchID | tickets | universityID   |
+---------+---------+----------------+
| 1       |     120 | Illinois       |
| 1       |     100 | IU Bloomington |
| 2       |     140 | Illinois       |
| 2       |      60 | Purdue         |
| 3       |      20 | U of Minnesota |
| 3       |     220 | Michigan       |
| 4       |     300 | Michigan       |
| 4       |      80 | U of Minnesota |
| 5       |     180 | Iowa           |
| 6       |     120 | Purdue         |
| 6       |     210 | IU Bloomington |
| 7       |     150 | IU Bloomington |
| 7       |     200 | Iowa           |
| 8       |     180 | Illinois       |
| 9       |     120 | U of Minnesota |
| 9       |      40 | Illinois       |
| 10      |     200 | Purdue         |
| 11      |     120 | Iowa           |
| 11      |      80 | Purdue         |
| 12      |      60 | IU Bloomington |
| 12      |      60 | U of Minnesota |
| 12      |     240 | Michigan       |
+---------+---------+----------------+
22 rows in set (0.00 sec)

mysql> exit
Bye
burrowww.cs.indiana.edu% exit
burrowww.cs.indiana.edu% 
script done on Tue Aug 03 09:14:11 2004

Mon Aug 2
Also, the environment variables for Tomcat 5 should be set to:
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
Also, here's the message of yesterday:
Date: Sun, 1 Aug 2004 16:34:10 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: a348sum2004 <dgerman@cs.indiana.edu>
Subject: last full week of classes

Dear A348/A548 Friends,

Each one of us should have received an individualized message from
us on Friday. We have 4 students in top condition, 3 in likely no risk
condition, 2 in small risk condition, and 4 students highly at risk, w/
one student on the fence between high risk and small risk, but going up
since Friday. Overall statistics are as of last Thu.

This coming week please make appointments as suggested. We should be
clear on this by the time the lab ends on Monday. These appointments are
ways for us to help you. Not a testing event, none of them. This week in
lecture we will cover

a) Tomcat 5.0.27 (one last time) as posted on What's New last week
b) Javascript
c) Final Exam and part two of the project
d) Homework Three and
e) Flash MX games implemented on top of NaradaBrokering (grid computing)
g) Java RMI and distributed computing

I truly hope you'll make appointments in time so we can help if need be.

... Adrian

Sat-Sun Jul 31-Aug 1
For Tomcat 5 here's my server.xml.

<Server port="11501" shutdown="SHUTDOWN">
  <GlobalNamingResources>
    <!-- Used by Manager webapp -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
      description="User database that can be updated and saved">
    </Resource>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector port="11500" />

    <!-- This is here for compatibility only, not required -->
    <Connector port="8009" protocol="AJP/1.3" />

    <Engine name="Catalina" defaultHost="localhost">
      <Logger className="org.apache.catalina.logger.FileLogger" />

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase" />

      <Host name="localhost" appBase="webapps">

        <Context path="/one" docBase="one" debug="0" reloadable="true" />

        <Context path="/" docBase="ROOT" debug="0" reloadable="true" />

      </Host>
    </Engine>
  </Service>
</Server>

(It's based on server-minimal.xml).

Also, here's my context one.

burrowww.cs.indiana.edu% pwd
/nfs/paca/san/r1a0l1/dgerman/tomcat/jakarta-tomcat-5.0.27/webapps
burrowww.cs.indiana.edu% du -a one
2       one/WEB-INF/classes/One.java
3       one/WEB-INF/classes/One.class
6       one/WEB-INF/classes
1       one/WEB-INF/lib
1       one/WEB-INF/web.xml
9       one/WEB-INF
1       one/one.jsp
11      one
burrowww.cs.indiana.edu% 
It comes with a web.xml file.

<?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>

</web-app>
Also with a servlet and a JSP.

Here's the servlet:

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

public class One extends HttpServlet {
    public void doGet(HttpServletRequest req,
                      HttpServletResponse res)
        throws ServletException,
               IOException {
        res.setContentType("text/html");
        HttpSession who = req.getSession();
        Integer balance = (Integer)who.getAttribute("balance");

        String arg = null, fun = null;
        int aux = 0;

        if (balance == null) {
            who.setAttribute("balance", new Integer(0));
        } else {
            arg = req.getParameter("arg");
            fun = req.getParameter("fun");
            aux = balance.intValue();
            if (fun.equals("add")) { aux = aux + Integer.parseInt(arg); }
            else { aux = aux - Integer.parseInt(arg); }

            who.setAttribute("balance", new Integer(aux));

        }

        PrintWriter out = res.getWriter();

String me = req.getContextPath() + req.getServletPath();

out.println(
"<form action=" + me + ">" +
"  Your balance currently is: " + aux + " <p>" +  
"  Please specify an amount <input type=text name=arg> <p> " +
"  Then choose an action: <select name=fun>" +
"    <option value=non> Click me! " +
"    <option value=add> Deposit   " +
"    <option value=sub> Withdraw  </select> <p>" +
"  When ready please press <input type=\"submit\"> " +
"</form> "
);

    }
}

Here's the JSP:

<%      Integer balance = (Integer)session.getAttribute("balance");
        String arg = null, fun = null;
        int aux = 0;
        if (balance == null) {
            session.setAttribute("balance", new Integer(0));
        } else {
            arg = request.getParameter("arg");
            fun = request.getParameter("fun");
            aux = balance.intValue();
            if (fun.equals("add")) { aux = aux + Integer.parseInt(arg); }
            else { aux = aux - Integer.parseInt(arg); }
            session.setAttribute("balance", new Integer(aux));
        }
        String me = request.getContextPath() + request.getServletPath();
%>

<form action=<%=me%>>
  Your balance currently is:<%=aux%><p>
  Please specify an amount <input type=text name=arg> <p>
  Then choose an action: <select name=fun>
    <option value=non> Click me!
    <option value=add> Deposit   
    <option value=sub> Withdraw  </select> <p>
  When ready please press <input type="submit">  
</form>

Everything exactly as in the notes, plus or minus a few specific details.

Fri Jul 30
Together with Fulya we agreed on the following approach:


So here's a picture of Fulya in case you haven't been to lab in a long time.

Thu Jul 29
Tomcat 5 is also available for download:
frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/software
frilled.cs.indiana.edu%ls -ld jak*
-rw-r--r--  1 dgerman faculty  4241667 Mar  5  2003 jakarta-tomcat-4.0.4.tar.gz
-rw-r--r--  1 dgerman faculty  7894019 Jul 28 01:20 jakarta-tomcat-4.1.30.tar.gz
-rw-------  1 dgerman faculty 10298374 Jul 28 11:24 jakarta-tomcat-5.0.27.tar.gz
frilled.cs.indiana.edu
It is likely to be the preferred way of programming server-side Java this semester.

I have installed Tomcat 5 also on the demo web site.

If you decide to install it on your own please use server-minimal.xml as your configuration file.

Not only that but your should work on /nobackup and transfer everything in your account at the end.

Wed Jul 28
Tomcat 4.x is available in
/l/www/classes/a348/software/jakarta*

Mon-Tue Jul 26-27
Here's the JSP developed in class on Tue:
<html><head><title>JSP Stage One</title></head>
<body bgcolor="white">

  <% int balance; 
     try {
       balance = Integer.parseInt(request.getParameter("balance")); 
       if (request.getParameter("fun").equals("add")) {

         balance += Integer.parseInt(request.getParameter("arg"));

       } else { 

         balance -= Integer.parseInt(request.getParameter("arg"));

       } 
     } catch (Exception e) {

       balance = 0; 

     } 
   %> <p>
 
  <form>
    Your balance is: <%= balance %> <p> 
    Specify an amount: <input type="text" name="arg"> <p> 
    Choose an operation: <select name="fun"> 
      <option value="non"> Click me!
      <option value="add"> Deposit
      <option value="sub"> Withdraw 
    </select> <p> 
    <input type="hidden" name="balance" value="<%=balance%>"> 
    <p> When done please press <input type="submit" value="Proceed">
  </form>
</body>
</html>

Sat-Sun Jul 24-25
Lecture and lab notes to be updated soon.

Meanwhile let me acknowledge the very good performance of

Ben Higgins Ning Liu Nick DePersio Pedro Daccarett Jesse Miles Mengyu Zhai

They are Students of the Month for the month of July.

Fri Jul 23
All of the past two weeks' midterm practice is now indexed here.

The midterm exam has also been posted in the Class Notes page.

Thu Jul 22
Here's the code we mentioned in class yesterday:
http://www.cs.indiana.edu/classes/a348/spr2004/pprrckscs.html

Wed Jul 21
Date: Wed, 21 Jul 2004 14:04:50 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A348 Summer 2004 Distr. List <dgerman@indiana.edu>
Subject: A348 Midterm Exam tomorrow


Dear A348/A548 Friends,

The Midterm Exam is tomorrow in class. Come as you are. The exam is open
book, open notes, individual work. You will receive a problem that is very
much like the one we have been discussing recently. I remind you here what
the problem we discussed recently was:

  http://www.cs.indiana.edu/classes/a348-dger/spr2002/exams/midterm.html

Your problem tomorrow will be similar.

The goal tomorrow will be to turn in a flowchart and a design document. I
will make copies of your exams and return them to you in lab. The written
part only has to describe the approach, clearly explaining those parts of
the solution that are problem-specific, and those that are implementation
specific (in which case a committment must be made in class---whether you
will implement with php or perl/cgi, with sessions or with hidden fields).

Then you will have until Monday to provide three implementations.

And until next Thursday to provide all four of them.

Next week we review the DBI/sessions in CGI/Perl one more time since we
didn't finish it today, then cover Javascript, Tomcat with servlets and
JSP and multiplayer games with Flash MX and Java. And that's it.

The final exam (when time comes) will be just like the midterm, but the
range of implementations will be: Javascript/DHTML, Java servlets, JSP,
where the last two approaches could be done client side or server side,
with sessions.

I will update the gradebook overnight and will be in touch with you
tomorrow in lab (as well as on Monday) with details on what you're doing,
what you should be doing, and how, as well as your overall standing in the
course.

So, see you tomorrow (Ryan too).

... Adrian

Tue Jul 20
Here's the program worked out in class yesterday.

Today in class we will take a new practice exam and finish the one from yesterday.

Mon Jul 19
Here's a final exam review used last year.

Sun Jul 18
Here's a tidbit we always forget to mention:

Creating a table that has a combination of columns as the primary key:

create table catboo (
  isbn char(6), 
  catid int unsigned, 
  primary key (isbn, catid)
) 
Don't forget that the columns that comprise the key must be not null.

Sat Jul 17
Example of an older midterm exam, good practice for this week's.

Fri Jul 16
Example of an exam problem:

So what's the benefit of the last approach if it's that long and complicated?

Thu Jul 15
Here's some help with Homework Three.

Two programs extracting information from the database:

Here's a script to create tables and populate them with data:

#!/usr/bin/perl

use DBI; 

$DB        = "DBI:mysql:a348";      # data source name (database)
$username  = "a348";                # username
$password  = "a348AG";              # password

$dbh = DBI->connect($DB, 
                    $username, 
                    $password, {PrintError => 0}) || 
       die "Couldn't open database: ", $DBI::errstr; 

print "I have opened the database...\n"; 

$query = qq{ 
  create table dgerman_HW3_players (
    username   varchar(8) primary key, 
    firstName  varchar(20), 
    lastName   varchar(20), 
    picture    varchar(120), 
    address    varchar(120), 
    city       varchar(30), 
    state      varchar(2), 
    playerRatePerMatch 
               decimal(12, 2)
  )
};   

print " Getting ready to create dgerman_players... "; 

$dbh->do($query) || die $dbh->errstr;

print "done.\n Getting ready to populate tables with data. \n"; 

open (INPUT, "players_data"); 
$line = <INPUT>; 
@names = split(/,/, $line); 
while ($line = <INPUT>) {
  ($uname, $first, $last, $pic, $addr, $city, $st, $rate) = 
                                             split(/,/, $line, 8); 
  $st =~ s/\s//g; 
  chop($rate); 
  $query = qq{
    insert into dgerman_HW3_players values 
      ('$uname', 
       '$first', 
       '$last', 
       '$pic', 
       '$addr', 
       '$city', 
       '$st', 
       $rate 
      )
  }; 

  # print $query, "\n"; 

  $dbh->do($query) || die $dbh->errstr; 

}
close(INPUT); 
Here it is in action, together with the data it needs:
burrowww.cs.indiana.edu% ls -l
total 6
-rw-r--r--   1 dgerman  faculty       704 Feb 19 11:50 players_data
-rwx------   1 dgerman  faculty      2438 Feb 19 11:50 script
burrowww.cs.indiana.edu% ./script
I have opened the database...
 Getting ready to create dgerman_players... done.
 Getting ready to populate tables with data. 
burrowww.cs.indiana.edu% cat players_data
username, firstName, lastName, picture , address             , city        , state, playerRatePerMatch 
cbarkley, Charles  , Barkley , some URL, Sir Charles Avenue  , Phoenix     , AZ   ,         450.00 
lbird   , Larry    , Bird    , some URL, Freedom Lick Rd.    , Naples      , FL   ,         350.00 
mjordan , Michael  , Jordan  , some URL, Jordan Air Way      , Chicago     , IL   ,         500.00 
rmiller , Reggie   , Miller  , some URL, Miller Time Road    , Indianapolis, IN   ,         150.00 
tduncan , Tim      , Duncan  , some URL, Duncan at the Tim   , Houston     , TX   ,         210.00 
tkukoc  , Toni     , Kukoc   , some URL, Petar Zrinski Street, New Zagreb  , PA   ,          50.00 
burrowww.cs.indiana.edu% 
Here's what the database looks like now (and two queries):
mysql> describe dgerman_HW3_players;
+--------------------+---------------+------+-----+---------+-------+---------------------------------+
| Field              | Type          | Null | Key | Default | Extra | Privileges                      |
+--------------------+---------------+------+-----+---------+-------+---------------------------------+
| username           | varchar(8)    |      | PRI |         |       | select,insert,update,references |
| firstName          | varchar(20)   | YES  |     | NULL    |       | select,insert,update,references |
| lastName           | varchar(20)   | YES  |     | NULL    |       | select,insert,update,references |
| picture            | varchar(120)  | YES  |     | NULL    |       | select,insert,update,references |
| address            | varchar(120)  | YES  |     | NULL    |       | select,insert,update,references |
| city               | varchar(30)   | YES  |     | NULL    |       | select,insert,update,references |
| state              | char(2)       | YES  |     | NULL    |       | select,insert,update,references |
| playerRatePerMatch | decimal(12,2) | YES  |     | NULL    |       | select,insert,update,references |
+--------------------+---------------+------+-----+---------+-------+---------------------------------+
8 rows in set (0.00 sec)

mysql> select firstName, lastName, city, playerRatePerMatch from dgerman_HW3_players;
+-----------+----------+---------------+--------------------+
| firstName | lastName | city          | playerRatePerMatch |
+-----------+----------+---------------+--------------------+
|  Charles  |  Barkley |  Phoenix      |             450.00 |
|  Larry    |  Bird    |  Naples       |             350.00 |
|  Michael  |  Jordan  |  Chicago      |             500.00 |
|  Reggie   |  Miller  |  Indianapolis |             150.00 |
|  Tim      |  Duncan  |  Houston      |             210.00 |
|  Toni     |  Kukoc   |  New Zagreb   |              50.00 |
+-----------+----------+---------------+--------------------+
6 rows in set (0.00 sec)

mysql> select * from dgerman_HW3_players;
+----------+-----------+----------+-----------+-----------------------+---------------+-------+--------------------+
| username | firstName | lastName | picture   | address               | city          | state | playerRatePerMatch |
+----------+-----------+----------+-----------+-----------------------+---------------+-------+--------------------+
| cbarkley |  Charles  |  Barkley |  some URL |  Sir Charles Avenue   |  Phoenix      | AZ    |             450.00 |
| lbird    |  Larry    |  Bird    |  some URL |  Freedom Lick Rd.     |  Naples       | FL    |             350.00 |
| mjordan  |  Michael  |  Jordan  |  some URL |  Jordan Air Way       |  Chicago      | IL    |             500.00 |
| rmiller  |  Reggie   |  Miller  |  some URL |  Miller Time Road     |  Indianapolis | IN    |             150.00 |
| tduncan  |  Tim      |  Duncan  |  some URL |  Duncan at the Tim    |  Houston      | TX    |             210.00 |
| tkukoc   |  Toni     |  Kukoc   |  some URL |  Petar Zrinski Street |  New Zagreb   | PA    |              50.00 |
+----------+-----------+----------+-----------+-----------------------+---------------+-------+--------------------+
6 rows in set (0.01 sec)

mysql> 
Now you need to extract data from (and present it into) a browser.

Wed Jul 14
Today in class we discussed the transformation from session to client based state-maintenance programs:
burrowww.cs.indiana.edu% diff ref.php two.php
1,4c1,3
< <? session_start(); 
<    $limit = 4; // guess the number in four tries... 
<    if (session_is_registered("message")) { 
<      // echo "I know you, I've seen you before."; 
---
> <? // $message, $number, $attempts is the state 
>    $limit = 4; 
>    if ($message) { 
33,35d31
<      session_register("message"); 
<      session_register("number"); 
<      session_register("attempts"); 
47,48c43,47
<      Please enter a guess: <input type="text" name="guess"> 
<    </form> 
---
>      Please enter a guess: <input type="text" name="guess">
>      <input type="hidden" name="message"  value="<?=$message?>"> 
>      <input type="hidden" name="number"   value="<?=$number?>"> 
>      <input type="hidden" name="attempts" value="<?=$attempts?>"> 
>    </form>
burrowww.cs.indiana.edu% 
This just shows the minimal differences.

We also discussed stamped transactions for server-side state.

The code will be linked here promptly.

(For the simplest stamps-based example see this folder).

Tue Jul 13
Here's the code developed in class today: program, source code.

Fri-Mon Jul 9-12
Here's the flowchart for the pattern we're promoting:

Wed-Thu Jul 7-8
I am in Los Angeles for a conference presentation.

In my absence Fulya will take care of the lecture and lab.

I present something along these lines at ICPADS 2004.

(Accepted papers/conference program, will give you my paper).

We will go over it in A348 when I return too.

Tue Jul 6
Here's where you can read some more about CGI.pm

Here's the template expressed in CGI.pm

Also note that in Spring Homework Two was slightly more complicated.

Here are two solutions to it:

in both cases using the pattern we're trying to stimulate into your minds (and suggest to you).

Here's where we start with our study of PHP.

Sat-Mon Jul 3-5
INDEPENDENCE DAY. No classes.

Here's the pattern we announced, used here to implement the guess the number in 10 tries game:

#!/usr/bin/perl
use CGI; 
$query = new CGI; # data is collected
$me = $ENV{SCRIPT_NAME}; 

#-----------------(outside of the pattern)---
# Step 0. Define state: (1) number to guess, 
#                       (2) no. of attempts (thus far) but also 
#                       (3) the last message we posted (for the user)
#
# Step 1. Retrieve state. 
$number = $query->param('number'); 
$attempts = $query->param('attempts'); 
$message = $query->param('message'); # this helps with state is empty? 

#
# Step 2. Check if state is empty (missing numbers are treated as zero!) 
#                                 That's why we check message instead... 
if (! $message) { # Step 2.1 State is empty---so we need to initialize it.
  $number = int(rand(100)); 
  $message = "Welcome to the game."; 
  $attempts = 0;  # thus far.
                  #
} else {          # Step 2.2 State is not empty. Process it using user input. 

  # Step 2.2.1 Get user input.   
  #
  $guess = $query->param('guess'); 

  # Step 2.2.2 Process (update/change) state. 
  #
  $attempts += 1; 
  if ($guess > $number) { 
    $message = "Please try lower.";     
  } elsif ($guess < $number) {
    $message = "Please try higher."; 
  } else { 
    $message = "Congratulations, you won."; 
    $number = int(rand(100)); 
    $attempts = 0; # new game starts   
    $message .= "<p> Welcome to a new game. "; # concatenation 

  }  
  if ($attempts >= 10) { # you lost... 
    $message = "Darn. You're out of tries. You lose."; 
    $number = int(rand(100)); 
    $attempts = 0; # new game starts   
    $message .= "<p> Welcome to a new game. "; # concatenation 
  } # else just keep going   

}

# Steps 3-4. Store and report the state. 
# 

print $query->header;
print $query->start_html;
print qq{<form action=$me>}, # state is reported below 
      qq{ 
  $message <p> 
  The number to guess is $number (for debugging purposes) <p> 
  Your attempts so far:}, $attempts + 0, qq{ (out of 10) <p> },
                            
                             # state is stored for later below 

qq{ 
  <input type="hidden" name="message" value="$message">
  <input type="hidden" name="number" value="$number">
  <input type="hidden" name="attempts" value="$attempts">
},                           
                             # and we're getting ready for more input...
qq{ 
  Your guess: <input type="text" name="guess"> <p>

  When ready please press <input type="submit" value="Proceed"> 
</form> 
};  
print $query->end_html; 
The code above uses the CGI.pm library that we will study this upcoming week.

Fri Jul 2
PHP to be installed is located (can be found in):
frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/software/php
frilled.cs.indiana.edu%ls -ld *
-rw-r--r--  1 dgerman faculty 4832738 Jun 14 00:19 php-4.3.7.tar.gz
frilled.cs.indiana.edu%
One extra change needs to be made to php.ini:
register_globals = On
But we also need to be aware of potential security problems as well.

Thu Jul 1
Installation of PHP will be described.

Here's Ning's program from Lab Two:

#!/usr/bin/perl
 
$script = $ENV{"SCRIPT_NAME"};

@images = ("lh08.gif", "lh07.gif", "lh09.gif", "lh01.gif");  

$index=$ENV{'QUERY_STRING'};
$nextindex=($index+1)%4;
$previndex=($index-1)%4;

$imgname = $images[$index]; 

&printTop;
 
print qq{<p> The image below has index $index. 
<p> The name of the image is $imgname. <p>};
  
print qq{<a href="$script?$previndex">prev</a>}; 

print qq{<img src="http://www.cs.indiana.edu/dept/img/$imgname">};

print qq{<a href="$script?$nextindex">next</a>}; 

&printBottom;

sub printTop { 
  print qq{Content-type: text/html\n\n<html>
  <head>
  <title>
  Lab Assignment 2
  </title>
  </head>
  <body bgcolor=white>
  <h1>Hello!</h1>};
}

sub printBottom {
  print qq{<p></body></html>};
}

Wed Jun 30
Homework Three has been posted.

Here's the simple program described in class today.

#!/usr/bin/perl

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

print qq{<html>}; 

$scriptName = $ENV{SCRIPT_NAME}; 

$input = $ENV{QUERY_STRING}; 

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

foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair); 
  $in{$name} = $value; 
}

$balance = $in{balance}; 

$balance += 1; 

print qq{

  Input received: ($input) <p> 

  The current balance is: $balance <p> 

  <form action="$scriptName">
    
    <input type="hidden" name="balance" value="$balance"> 

    <input type="submit" value="Proceed">     
  </form> 
  </html>}; 

Mon-Tue Jun 28-29
Here's the most important part of what we developed in class on Mon and Tue:
#!/usr/bin/perl

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

print qq{
  <html><head><title>Lindley Portfolio</title></head><body bgcolor="white"> 
};

$def = "http://www.cs.indiana.edu/l/www/classes/a202-dger/sum99/a202.gif"; 

%pics = ( "lh07" => "http://www.cs.indiana.edu/dept/img/lh07.gif", 
          "lh01" => "http://www.cs.indiana.edu/dept/img/lh01.gif", 
          "lh08" => "http://www.cs.indiana.edu/dept/img/lh08.gif", 
          "lh09" => "http://www.cs.indiana.edu/dept/img/lh09.gif" );

$me = $ENV{SCRIPT_NAME}; 

$one = qq{ <a href="$me?lh07">Lindley One</a> }; 
$two = qq{ <a href="$me?lh01">Lindley Two</a> }; 
$thr = qq{ <a href="$me?lh08">Lindley Three</a> }; 
$fou = qq{ <a href="$me?lh09">Lindley Four</a> }; 

$pic = $def; 
$cap = "Picture of Dilbert working hard in Lindley."; 

$input = $ENV{QUERY_STRING}; 

%caps = 
        ( "lh07" => "You're looking at picture seven", 
          "lh01" => "Picture One is here", 
          "lh08" => "Eight. This is eight.", 
          "lh09" => "Last picture number nine." );

if ($input eq "lh07") { $one = "Lindley One";   $pic = $pics{lh07}; $cap = $caps{lh07}; } 
if ($input eq "lh01") { $two = "Lindley Two";   $pic = $pics{lh01}; $cap = $caps{lh01}; }  
if ($input eq "lh08") { $thr = "Lindley Three"; $pic = $pics{lh08}; $cap = $caps{lh08}; } 
if ($input eq "lh09") { $fou = "Lindley Four";  $pic = $pics{lh09}; $cap = $caps{lh09}; } 

print qq{
  <table border cellpadding=2>
    <tr> <td> $one <td> $two <td> $thr <td> $fou 
    <tr> <td colspan=4 align=center> <img src="$pic"> 
    <tr> <td colspan=4 align=center> $cap 
  </table>
  </body></html>
}; 

Sun Jun 27
Also congratulations for completing Lab One very well to:

Pedro Daccarett Jesse Miles Andy Stewart Peter Uthuppuru Mengyu Zhai

Congratulations for completing Homework One well (and in advance) to:

Ben Higgins Chip Sharp Ning Liu Nick DePersio

Sat Jun 26
Gradebook created, initialized (in OnCourse).

Fri Jun 25
Check here to find out if your Lab One appears to be turned in correctly.

Don't forget to set the permissions right:

chmod 711 ~
chmod 755 ~/public
chmod 644 whoa.tar.gz

Thu Jun 24
For a description of Homework One please check out my server.

Wed Jun 23
My office hours will be 10:45-11:30am daily (MTWRF) in LH201D.

And Fulya's will be Mon and Thu after lab (12:20-1:20pm) in BH118.

Tue Jun 22
Assignments of port numbers posted.

Lecture Notes Two, describing the installation of Apache.

Mon Jun 21
Second Summer session starts today.

Here are the notes for Lecture One and Lab One.

Here's a link to the virtual library and to many web-related tutorials.


Updated by Adrian German for A348/A548