Fall Semester 2007

Sat-Sun Dec 08-09
Updates on a JSP posted three weeks ago. Why is this relevant?

Code developed in lab yesterday with Mike Jindra and Aaron Ofengender. So, what about it?

Fri Dec 07
Example of a JSP that prevents accidental reloads:

	String me = request.getContextPath() + request.getServletPath(); // who am I? 
	String count = (String) session.getAttribute("count"); // retrieve state   
        Integer stamp = (Integer) session.getAttribute("stamp"); // this part is new (retrieve state) 
	int index = (count == null) ? 0 : Integer.parseInt(count); // initialize state 
        if (stamp == null) { stamp = new Integer(0); } 

        String whichWay = request.getParameter("fun"); // read input to change state (part I)
        if (whichWay == null) { // protecting against bad input 

	} else {

	    // the empty string is different from null!

            String userStamp = request.getParameter("stamp"); // read user's stamp (part of input) 
            boolean match; 
            try {
              match = (stamp.intValue() == Integer.parseInt(userStamp)); 
            } catch (Exception e) { match = false; } // comparing the stamps 

            if (match) { 

      	      String arg = request.getParameter("arg"); // reading input to change state (part II) 

	      if (whichWay.equals("up")) { // changing the state one way or another 

		index += Integer.parseInt(arg); 

	      } else if (whichWay.equals("down")) {

		index -= Integer.parseInt(arg); 

	      } else {

		// something went wrong (we don't do anything) 


              stamp = new Integer(stamp.intValue() + 1); 
              session.setAttribute("count", index + ""); // save state 
              session.setAttribute("stamp", stamp); // save the stamp (it's part of the state) 

           }  else { 


  <head><title>My Last JSP</title></head>

  <body bgcolor=white><table>

    <form method="GET" action="<%=me%>"> 

      The result is currently: <%=index%> <p> 
	 <input type="text" name="arg" size=4>

      Please choose an action: <select name="fun"> 
        <option value="nothing"> Click Me! 
        <option value="up"> Addition 
        <option value="down"> Substraction
      </select> <p> 

      Then press <input type="submit" value="Proceed"> 

      <input type="hidden" name="stamp" value="<%=stamp%>"> 




Thu Dec 06
Code developed in class today works like a charm: one, two.

Chapter 13 code, code from Tue class, will show up here soon.

Wed Dec 05
Final exam is next Thu, Dec 13, between 7:15-9:15pm, in LH201D (double check here).

Here's the script to make individual appointments.

Fri Nov 30
So I have been asked if I can offer some more help with Homework Four.

The code below would be my contribution. What do you think of it?


if ($fl_gs) {

$flags explode(','$fl_gs);
$flaeg array_pop($flags);

$flags implode(','$flags);

 } else {
$initial = array("one""two""three");
$flags implode(','$initial);



<font color="#0066cc"><?=$flaeg?></font>

<input type="submit" value="Proceed">

<input type="hidden" name="fl_gs" value="<?=$flags?>">


JDBC notes from the past.

Thu Nov 29
Code developed Tue in class:

Wed Nov 28
Data for Homework Three if you're still working on it.

Recall the project blog, notes for homework three already have what you need.

The new thing in the link above is just the format of this data, text here.

Getting data in, and out of the database (you've seen these scripts before).

Mon-Tue Nov 26-27
Tomorrow: wrap up Homework Seven, servlets.

Labs this week: JDBC from servlets.

Next week: project concludes with a discussion of multi-screen apps (ch. 13 in text).

Wed-Sun Nov 21-25
Thanksgiving Recess.

Mon-Tue Nov 19-20
Code developed on Tue, in class:

Sat-Sun Nov 10-18
One can start to understand Java syntax for servlets and JSPs as follow:

Fri Nov 9
Thoughts about Homework Six (credit goes to Jim Klotz).

Tue-Thu Nov 6-8
Tuesday's class notes (due to the outage we reviewed the essential Java we need).

Notes to be used today in class:

Once this is done we can look at an older project:

Relevant for the lab this week:

A JSP that implements the Flag Quiz.

Thu-Fri Nov 1-2
Six pages about Tomcat installation:

Wed Oct 31
Code developed in class yesterday (check the source code).

Tue Oct 30
This week in lab we install Tomcat, introduce Java, Java servlets and JSP (Java Server Pages).

Please read chapters 17, 16, 18 in your text.

Sat-Sun Oct 27-28
Complete description of all assignments for the semester posted on What's Due?

Fri Oct 26
Grades, update on assignments for the semester, project to be posted today.

Thu Oct 25
Lecture Notes to support Chapter 15 in the text.

Lab Notes for this week.

Here's an example from Chapter 15, and another one from the same chapter.

More code, and some more (simple examples the lab could discuss).

Thu Oct 18
Midterm Exam was administered in class today.

Tue Oct 16
Code we started from.

Fri-Mon Oct 13-15
Things we have developed in lab this week:

Thu Oct 11
Lab this week covers pp. 61-66 (preparation for the exam next week).

Here's a program you might want to develop three ways (CGI/Perl hidden, PHP with and without sessions).

Fri-Wed Oct 5-10
Wrapping up the discussion about keeping state on the web: part a), part b).

All links in the material for the lab last week work now.

Tue-Thu Oct 2-4
The blog is growing, it will soon be finished.

Materials for this week's lab are to be found here.

Sat-Mon Sep 27 -Oct 01
I spoke about creating a blog for your projects.

This week we give you an example. Take a look, here.

Wed-Fri Sep 26-28
Pp. 51-66 in the text: PHP game, CGI/perl conversion.

Tue Sep 25
Database design and SQL notes:

More to come soon, including Homework Three.

Mon Sep 24
Reading assignment for this week: chapter 10, pp. 51-66.

Basic framework we're trying to develop:

Sat-Sun Sep 22-23
Flag images for Homework Two, Four.

Fri Sep 21
Specifics for database connection for this semester (please use your port and password):

use DBI; 
use CGI; 

$q = new CGI; 

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

$DB        = "dbi:mysql:demoOne:silo.cs.indiana.edu:port=14518"; 
$username  = "dgerman";             
$password  = "sp00n"; # put your own password, you can see mine if you highlight it

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

$query = "select * from players"; 

$sth = $dbh->prepare($query) || die $dbh->errstr;

$sth->execute() || die $sth->errstr;

Programs that you might want to test your PHP with:

<? session_start();
   if ($message) {
     $balance += $amount; 

     $message = "Balance is currently: " . $balance;

   } else { // initialize state 
     $message = "Balance is: "; 

     $balance = 0; 
     $message .= $balance; 

  <?=$message?> <p> 

  Amount to add: <input type="text" name="amount" size=4> <p>

  Press <input type="submit" value="Proceed"> when ready. 
This is similar to the one above, just uses client-side state:

   if ($message) {
     $balance += $amount;
     $message = "Balance is currently: " . $balance;
   } else { // initialize state
     $message = "Balance is: ";
     $balance = 0;
     $message .= $balance;
  <?=$message?> <p>

  Amount to add: <input type="text" name="amount" size=4> <p>
  Press <input type="submit" value="Proceed"> when ready.
  <input type="hidden" name="message" value="$message">
  <input type="hidden" name="balance" value="$balance">

We will explain them both, very thoroughly this coming week.

Wed-Thu Sep 19-20
Let's wrap up all the installations for this half of the semester by installing PHP:

Here's some code you could use directly:

./configure \
  --with-mysql=/nobackup/dgerman/mysql \
  --with-apxs2=/u/dgerman/apache/bin/apxs \
  --with-config-file-path=/u/dgerman/apache/conf \
  --with-xml --enable-track-vars \
The two lines you need to add to httpd.conf:
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps

The notes on the class notes page will not add much more to what's posted here.

Tue Sep 18
Add this line as the last but one command line argument to your mysql_start batch file:
--log-error=/nobackup/dgerman/mysqld-error.log \
Careful to put your username instead of mine.

Sat-Mon Sep 15-17

Steps for installing MySQL: one, two, three, four.

Another set of notes with a shorter sequence of steps.

More to come soon.

Tue-Fri Sep 11-14

Steps for installing a protected folder: one, two.

Code we developed in class on Thu: one, counter.

Program that should be relevant to Homework Two: shuffle (see it running here).

Sample programs we are interested in this week:

Sat-Mon Sep 8-10
Other notes to be used this week:

Sat-Mon Sep 8-10
Notes for this week posted.

Fri Sep 7
Is your lab 1 archive accessible? Find out here.

Thu Sep 6
Shakila's office hours: TR 2:15-3:30pm in LH201D (right after class).

My office hours, as a reminder: MTWRF 10:00-11:30am in LH201D.

Wed Sep 5
A few links to be used in tomorrow's lecture:

Tue Sep 4
Things we will cover this week:

Here's the command prompt calculator:


$balance = 0; 
print "Your balance is: $balance\n"; 
print "Type> "; 
while ($line = <STDIN>) {
  ($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:

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>"; 
Wed Aug 29

Notes for this week have been posted.

Tue Aug 28
Class starts today at 1:00pm in Lindley Hall 102 (LH102).

Adrian's office hours:

Teaching assistant for this class: Ms. Shakila Shayan (office hours to be announced soon).

Required text for this class (avalable at IU Bookstore).

List of students and ports. Basic syllabus (specific details forthcoming).

Updated by Adrian German for A348/A548