|
Spring Semester 2006
|
Thu May 18
Thu-Fri May 4-6
Mon-Wed May 1-3Script for appointments is still here.Date: Wed, 3 May 2006 18:40:38 -0400 (EDT) From: Adrian German <dgerman@cs.indiana.edu> To: undisclosed-recipients: ; Subject: A348/A548 Final Exam tomorrow (LH102 @2:45-4:45pm). Dear A348/A548 Friends, The Final Exam is in class (LH102) between 2:45pm and 4:45pm tomorrow. The exam is closed book. The best review is your homework and lab work. Short questions will be asked about the material covered in class. The questions posted for your review are meant to give you an idea about the format not the content. Questions will be about things discussed in class and the work that you have put in your assignments. The class notes page has been changed. It now contains a brief review, with a link at the top to a complet set of notes very similar to the one we have used this semester. Also, don't forget to review the What's New? page, it contains code we developed in class and information posted on an almost daily basis. So that is I think a very close summary in a nutshell of what we have been through (as far as A348 material is concerned) this semester. Good luck tomorrow and please let me know if you have questions or need any help. ... Adrian
Fri-Sun Apr 28-30Here is a list of questions to think about when preparing for the final.
Thu Apr 27
Sat-Wed Apr 18-26
Fri-Mon Apr 15-17
Jun Yin. Individual appointments for the next two weeks can be scheduled through this script.
Thu Apr 14
Sarah Rieke in class on Thu:
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Three 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"), compScore = (String)session.getAttribute("compScore"), userScore = (String)session.getAttribute("userScore"), secret = (String)session.getAttribute("secret"), attempts = (String)session.getAttribute("attempts"), // state ends here answer = request.getParameter("answer"); // input String me = request.getContextPath() + request.getServletPath(); if (message != null) { int a = Integer.parseInt(answer), s = Integer.parseInt(secret), n = Integer.parseInt(attempts); if (a == s) { // they won message = "Good."; userScore = Integer.parseInt(userScore) + 1 + ""; attempts = "0"; secret = Math.round(Math.random() * 100) + ""; } else { n += 1; if (n == 10) { // they lost message = "Bad."; compScore = Integer.parseInt(compScore) + 1 + ""; attempts = "0"; secret = Math.round(Math.random() * 100) + ""; } else { if (a < s) { message = "Try higher."; } else { message = "Try lower."; } attempts = n + ""; } } } else { message = "The game has started."; session.setAttribute("message", message); secret = Math.round(Math.random() * 100) + ""; session.setAttribute("secret", secret); attempts = "0"; session.setAttribute("attempts", attempts); compScore = "0"; session.setAttribute("compScore", compScore); userScore = "0"; session.setAttribute("userScore", userScore); } session.setAttribute("message", message); session.setAttribute("secret", secret); session.setAttribute("attempts", attempts); session.setAttribute("compScore", compScore); session.setAttribute("userScore", userScore); out.println( "<form action=\"" + me + "\">" + " " + message + "<p>" + " secret: " + secret + "<p>" + " attempts: " + attempts + "<p>" + " (" + compScore + " - " + userScore + ") <p>" + " Type your answer here: <input type=\"text\" name=\"answer\"> <p> " + " Push <input type=\"submit\" value=\"Proceed\"> when ready. " + "</form>" ); } }The part in blue is the last step in the development.Do you know what name this part has in our template?
Thu Apr 13
Sat-Wed Apr 9-12
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Four extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String message = request.getParameter("message"),
compScore = request.getParameter("compScore"),
userScore = request.getParameter("userScore"),
secret = request.getParameter("secret"),
attempts = request.getParameter("attempts"), // state ends here
answer = request.getParameter("answer"); // input
String me = request.getContextPath() + request.getServletPath();
if (message != null) {
int a = Integer.parseInt(answer),
s = Integer.parseInt(secret),
n = Integer.parseInt(attempts);
if (a == s) { // they won
message = "Good.";
userScore = Integer.parseInt(userScore) + 1 + "";
attempts = "0";
secret = Math.round(Math.random() * 100) + "";
} else {
n += 1;
if (n == 10) { // they lost
message = "Bad.";
compScore = Integer.parseInt(compScore) + 1 + "";
attempts = "0";
secret = Math.round(Math.random() * 100) + "";
} else {
if (a < s) {
message = "Try higher.";
} else {
message = "Try lower.";
}
attempts = n + "";
}
}
} else {
message = "The game has started.";
secret = Math.round(Math.random() * 100) + "";
attempts = "0";
compScore = "0";
userScore = "0";
}
out.println(
"<form action=\"" + me + "\">" +
" " + message + "<p>" +
" secret: " + secret + "<p>" +
" attempts: " + attempts + "<p>" +
" (" + compScore + " - " + userScore + ") <p>" +
" Type your answer here: <input type=\"text\" name=\"answer\"> <p> " +
" Push <input type=\"submit\" value=\"Proceed\"> when ready. " +
" <input type=\"hidden\" name=\"message\" value=\"" + message + "\">" +
" <input type=\"hidden\" name=\"compScore\" value=\"" + compScore + "\">" +
" <input type=\"hidden\" name=\"userScore\" value=\"" + userScore + "\">" +
" <input type=\"hidden\" name=\"attempts\" value=\"" + attempts + "\">" +
" <input type=\"hidden\" name=\"secret\" value=\"" + secret + "\">" +
"</form>"
);
}
}
Mon-Fri Apr 2-7
classes folder
web.xml for the servlet
After lab this week we can get started with Homework Five (and Six follows right away).
Thu-Sun Mar 30-Apr 2#!/usr/bin/perl
use DBI;
use MD5;
use CGI;
$EXPIRE = 60 * 60 * 24 * 30; # allow 30 days before expiration
$DB = "DBI:mysql:a348"; # data source name (database)
$username = "a348"; # username
$password = "a348AG"; # password
$DBAUTH = "$username:$password";
$SECRET = " ***( something secret, whatever )*** ";
$MAX_TRIES = 10;
$DB_TABLE = "ckotil_firstta";
$ID_LENGTH = 8; # length of the session ID
$q = new CGI;
# Open the database --------------------------------------------------------
$DBH = DBI->connect($DB, $username, $password, {PrintError => 0}) || die "Couldn't open database: ", $DBI::errstr;
# get the current session ID, or make one ----------------------------------
my ($session_id, $note) = &get_session_id();
print $q->header,
$q->start_html(-title => 'Database Sessions with URL Rewriting',
-bgcolor => 'white');
# retrieve the state -------------------------------------------------------
my $state = &get_state($session_id) unless $q->param('clear');
$message = $state->{message};
$comp = $state->{comp};
$user = $state->{user};
$guess = $q->param('guess');
if ($message) {
$user += $guess;
if ($user >= 100) {
print "You WIN!";
$user=0;
} else {
$comp = 1 + int(rand(10)); # this is the number
$user=$user + $comp;
};
if ($user>=100) {
print "I WIN!";
$user=0;
}
} else {
$message = "Welcome";
$user = 0;
$comp = -1;
}
$state->{message} = $message;
$state->{comp} = $comp;
$state->{user} = $user;
# save the modified state --------------------------------------------------
&save_state($state, $session_id);
print qq{<form>
I have chosen $comp . <br>
The total is currently $user , remember first to 100 wins. <p>
How much will you enter? (0-10) <input type="text" name="guess"/> <p>
Press <input name="submit" type="submit" value="Submit"/> when ready to submit.
</form>};
print $q->end_html;
$DBH->disconnect;
# retrieve the session ID from the path info. if it's -----get_session_id---
# not already there, add it to the path info (more or less) with a redirect
sub get_session_id {
my (@result);
&expire_old_sessions();
my ($id) = $q->path_info() =~ m:^/([a-h0-9]{$ID_LENGTH}):o;
return @result if $id and @result = &check_id($id);
# if we get here, there's not already an ID in the path info
my $session_id = &generate_id();
die "Couldn't make a new session id" unless $session_id;
print $q->redirect($q->script_name() . "/$session_id");
exit 0;
}
# find a new unique ID and insert it into the database -------generate_id---
sub generate_id {
# create a new session id
my $tries = 0;
my $id = &hash($SECRET . rand());
while ($tries++ < $MAX_TRIES) {
last if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");
$id = &hash($id);
}
return undef if $tries >= $MAX_TRIES; # we failed
return $id;
}
# check to see that an old ID is valid --------------------------check_id---
sub check_id {
my $id = shift;
return ($id, '')
if $DBH->do("SELECT 1 FROM $DB_TABLE WHERE session_id = '$id'") > 0;
return ($id, 'The record of your game may have expired. Restarting.')
if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");
return ();
}
# generate a hash value ---------------------------------------------hash---
sub hash {
my $value = shift;
return substr(MD5->hexhash($value), 0, $ID_LENGTH);
}
sub expire_old_sessions { # --------------------------expire_old_sessions---
$DBH->do(<<END);
DELETE FROM $DB_TABLE
WHERE (unix_timestamp() - unix_timestamp(modified)) > $EXPIRE
END
}
# get the state from the database ------------------------------get_state---
sub get_state {
my $id = shift;
my $query =
"SELECT * FROM $DB_TABLE WHERE session_id = '$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;
}
# save the state in the database ------------------------------save_state---
sub save_state {
my ($state, $id) = @_;
my $sth = $DBH->prepare(<<END) || die "prepare: ", $DBH->errstr;
UPDATE $DB_TABLE
SET message=?,comp=?,user=?
WHERE session_id='$id'
END
$sth->execute(@{$state}{qw(message comp user)})
|| die "execute: ", $DBH->errstr;
$sth->finish;
}
This was developed based on Chad Kotil's code, there was one based on Nathan Adams' code too.
Wed Mar 29Please review the notes posted for Thu and Fri, labs will focus exclusively on Homework Four.
That is: keeping state with CGI using custom sessions and DBI for database access.
Tue Mar 28We start on server-side Java, JDBC and discuss the remaining hoemwork assignments.
Please check your grades in A348-0205, they have been updated Monday morning to include the exams.
Mon Mar 27The next few homework assignments are:
| Homework Four | The exam problem implemented with CGI/DBI and server side state |
| Homework Five | The exam problem implemented with servlets (hidden fields and session based) |
| Homework Six | The exam problem implemented using Java Server Pages (hidden fields and sessions) |
| Homework Seven | The exam problem implemented using Javascript and DHTML |
Due dates will be posted soon. Labs will be dedicated to helping with homework.
We also need to pay attention to the project, and your design documents are due this coming week, in lab.
More details on what is needed will be posted here and sent by e-mail to you Sun morning:
Date: Sun, 26 Mar 2006 09:28:51 -0500 (EST) From: Adrian German <dgerman@cs.indiana.edu> To: A348/A548 Spr. 2006 Distr. List <dgerman@indiana.edu> Subject: project design documents due in lab this coming week (03/30-31) As discussed in lab last week design documents for your projects are due in lab this coming Thu and Fri 03/30-31. You need to describe the screens and basic functionality of your project as if it's finished, and you want to pitch it for sale or funding to someone else (me, Craig and Minh). We will collect these documents and I will give you feedback by the Tue that follows (04/04). I will tell you how much is enough for A348/A548 and how I think you "implemented" it. It will be up to you to use the feedback in any way you want, and the most convenient implementation method for you but we would then have two more stages in which you would have to show us the project on the computer, as it's being developed. Tue we go back to Tomcat, Java servlets and Java Server Pages. The lecture on PHP/ColdFusion is canceled and we will instead discuss server-side Java, JDBC and Perl CGI/DBI. This will take care of the next 3 hw assignments (4, 5 and 6) after which we can approach the last assignment (7) which will be implementing the midterm exam problem using Javascript and DHTML. Grades up to Lab 10 and Homework 3 and the Midterm Exam are being posted. If you have any questions or need any help please let me know. ... Adrian
Sat-Sun Mar 25-26Next an announcement will be made regarding this coming lab and the remaining homework assignments.
Fri Mar 24~/.bash_profile before installation of Tomcat:
You should be using your own username, of course.EDITOR=pico export EDITOR PATH=/usr/local/gnu/bin:$PATH:/home/user1/mysql/bin export PATH JAVA_HOME=/l/jdk1.5 export JAVA_HOME CATALINA_HOME=/u/dgerman/tomcat/jakarta-tomcat-5.5.9 export CATALINA_HOME CLASSPATH=.:$CATALINA_HOME/common/lib/servlet-api.jar export CLASSPATH
Wed-Thu Mar 22-23
Tue Mar 21
web.xml very much like this:
<?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> Here's how you tell Tomcat to reload your servlets after you recompile them:
<Server port="15477" 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"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="15476" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase" />
<Host name="localhost" appBase="webapps">
<Context path="/nov09" docBase="nov09" debug="0" reloadable="true" />
</Host>
</Engine>
</Service>
</Server>
Sat-Mon Mar 11-20
Thu-Fri Mar 9-10
<? 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); } } ?>
Wed Mar 8
I will post more details as we get closer to those dates.
Krishna will also buy pizza and soft drinks for everybody for his lecture.
Tue Mar 7
As far as tables are concerned you can see how we got started here.
Here's the lab for this week:
Fri-Mon Mar 3-6
Thu Mar 2
Wed Mar 1
Mon-Tue Feb 27-28
Sun Feb 26 | There will be a review and help session in anticipation of the exam on Tue, in class. |
| Craig Shue will be teaching Tuesday's class and will be answering all your questions. |
Sat Feb 25
| Homework One (Apache, HTML) | Lab Assignment One (Unix, archiving) |
Homework Two
| Lab Assignment Two (Basic CGI/CGI.pm)
|
Homework Three:
| Lab Assignment Three:
|
Lab Assignment Four
| Lab Assignment Five:
|
Lab Assignment Six:
| Lab Assignment Seven:
|
Fri Feb 24
Thu Feb 23
Wed Feb 22
Tue Feb 21
Sun-Mon Feb 19-20
|
Sat Feb 18
|
<? session_start();
|
Thu-Fri Feb 15-16dgerman:xAzOFxiQYqKxE
Wed Feb 15
Tue Feb 14
here's the code developed in class today:
You must be able to start seeing how close these programs are to each other!
They're almost, almost identical.
Mon Feb 13
In class we will discuss server-side management of state (in general).
We will then develop tools to implement that using CGI/Perl and MySQL.
Sun Feb 12
Jun Yin Jun Yin's Spiffy Lab Five Program | Keira Johnson Keira Johnson's Homework Two | Jonathan Warren Jonathan Warren's Homework Two |
This list is not exhaustive by any means.
But I hope it is a source of inspiration to all of us.
Sat Feb 11
Fri Feb 10
Thu Feb 9A note from a former student.
Wed Feb 8
Sun-Tue Feb 5-7
Their prototype is the minute paper for Tue: this program developed with CGI.pm.
Sat Feb 4
Lab Assignment Two developed with
Tim Devlin in lab on Friday:
#!/usr/bin/perl
%images = (
"One" => "http://www.cs.indiana.edu/dept/img/lh01.gif",
"Seven" => "http://www.cs.indiana.edu/dept/img/lh07.gif",
"Eight" => "http://www.cs.indiana.edu/dept/img/lh08.gif",
"Nine" => "http://www.cs.indiana.edu/dept/img/lh09.gif"
);
@keys = ("One", "Seven", "Eight", "Nine");
use CGI;
$q = new CGI;
print $q->header, $q->start_html;
$index = $q->param('index'); # read the value for the parameter named index in the input
$action = $q->param('action');
if ($action eq "previous") {
$index = $index -1 ;
if ($index < 0) { $index = 3; }
} elsif ($action eq "next pic") {
$index = $index + 1;
if ($index >= 4) { $index = 0; }
} else {
$index = 0;
}
$key = $keys[$index];
$picture = $images{$key};
print qq{
<form>
<table>
<tr> <td> <input type="submit" name="action" value="previous">
<td align=right> <input type="submit" name="action" value="next pic">
<tr> <td colspan=2> You are looking at picture $key
<tr> <td colspan=2> <img src="$picture">
</table>
<input type="hidden" name="index" value="$index">
</form>
};
print $q->end_html;
Fri Feb 3php.ini after installation:
You should also create aregister_globals = On
phpsessions to keep session information in it.
Thu Feb 2Here's the PHP code we developed at the end of Thu's class:
<?
$balance += $amount;
?>
<form>
The current balance is: <? echo $balance; ?> <p>
Please enter the
amount here: <input type="text" name="amount"> <p>
Chooose an action: <select name="what">
<option value="none"> Click me!
<option value="deposit"> Deposit
<option value="withdraw"> Withdraw
</select>
<input type="hidden" name="balance"
value="<? echo $balance;
?>">
<p> Please press <input type="submit" value="Proceed"> when
ready.
</form>
Wed Feb 1#!/usr/bin/perl
@answers = ("zero", "one", "two", "three", "four", "five", "six", "seven");
use CGI;
$q = new CGI;
print $q->header, $q->start_html;
$times = $q->param('times');
$times += 0;
$action = $q->param('action');
$userInput = $q->param('userInput');
if ($answers[$times] eq $userInput) { # skip it first time around
$message = "Very good, that was the answer.";
} else {
$message = "Too bad, better be more careful next time.";
}
if ($action =~ /next/) { $times += 1; }
elsif ($action =~ /previous/) { $times -= 1; }
else { }
#--------------------(no printing above on purpose)-------
print qq{
<form>
<table>
<tr> <td> <input type="submit" name="action" value="previous">
<td> <input type="submit" name="action" value="next">
<tr> <td colspan=2> $message
<tr> <td colspan=2> You are looking at picture: $times <p>
<input type="hidden" name="times" value="$times">
<tr> <td colspan=2> Please type here the number you see:
<input type="text" name="userInput">
</table>
</form>
};
print $q->end_html;
Tue Jan 31In class we will discuss keeping state on the server side (tutorial 12 and the associated example).
Fri-Mon Jan 27-30CGI.pm which will come in handy shortly.
Thu Jan 26
Don't forget that Homework Two is just like the Lab Assignment Two program.
Except we also collect the answers, which we grade, and tally.
Wed Jan 25#!/usr/bin/perl
print qq{Content-type: text/html\n\n<html><head><title>CGI Processor</title><head><body bgcolor="white">};
&readParse;
foreach $k (keys %in) {
print $k, " --> ", $in{$k}, "<br>";
}
$input = $ENV{"QUERY_STRING"};
print qq{
($input) <hr>
<form>
<table border cellpadding=3>
<tr> <td> Field one: <td> <input type="text" name="one">
<tr> <td> Field two: <td> <input type="text" name="two">
</table> <p>
Please press <input type="submit" value="Proceed">
</form>
};
print qq{</body></html>};
sub readParse {
$user = $ENV{"QUERY_STRING"};
@pairs = split(/&/, $user);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair, 2);
$value =~ s/%(..)/chr(hex($1))/ge;
$in{$name} = $value;
}
}
The second program that starts us on the sequential portfolio:
#!/usr/bin/perl
print qq{Content-type: text/html\n\n<html><head><title>CGI Processor</title><head><body bgcolor="white">};
&readParse;
%images = (
"One" => "http://www.cs.indiana.edu/dept/img/lh01.gif",
"Seven" => "http://www.cs.indiana.edu/dept/img/lh07.gif",
"Eight" => "http://www.cs.indiana.edu/dept/img/lh08.gif",
"Nine" => "http://www.cs.indiana.edu/dept/img/lh09.gif"
);
$pic = "lh01.gif";
$pic = $in{"pic"} if ($images{$in{"pic"}});
if ($in{"Next"}) {
} elsif ($in{"Previous"}) {
} else {
}
print qq{
<form>
<table>
<tr>
<td> <input type="submit" name="previous" value="Previous">
<td> <input type="submit" name="next" value="Next">
<tr><td colspan=2> <img src="http://www.cs.indiana.edu/dept/img/$pic">
</table>
<input type="hidden" name="pic" value="$pic">
</form>
};
print qq{</body></html>};
sub readParse {
$user = $ENV{"QUERY_STRING"};
@pairs = split(/&/, $user);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair, 2);
$value =~ s/%(..)/chr(hex($1))/ge;
$in{$name} = $value;
}
}
Tue Jan 24Here's a framework we need to start understanding.
Mon Jan 23(They're mostly in the right places, they just need to be cleaned up a bit).
Sun Jan 22Click here to see if your archive is accessible.
Sat Jan 21
| Thursday lab 3:35pm-5:30pm Lindley Hall 115 Craig Shue (assisted by Minh Tang) |
| Friday first lab 10:10am-12:05pm Lindley Hall 025 Adrian German (assisted by Craig Shue) |
| Friday second lab
12:20pm- 2:15pm Lindley Hall 025 Minh Tang (assisted by Adrian German) |
Fri Jan 20chmod 711 ~ chmod 755 ~/public chmod 644 ~/public/whoa.tar.gz
Thu Jan 19~/.bash-profile file with two lines
EDITOR=pico
export EDITOR
From here on every time you login pico is your default editor.
Type crontab -e to use it to change your crontab entries.
Wed Jan 18
Tue Jan 17
Mon Jan 16Lab notes for this week will be finalized Tuesday night.
Sat-Sun Jan 14-15
Fri Jan 13
Thu Jan 12
Attendance (minute papers) is collected
here: A348-0205.
(PostEm will soon appear listed as a tool in OnCourse.)
Wed Jan 11has been moved to ED2015.CSCI-A 348/A548 (14754/14764) R 3:35PM - 5:30PM
Please make a note of it (location is close to the original venue).
Tue Jan 10
Mon Jan 9
LEC 1:00pm- 2:15pm TR LH102 German LAB 3:35pm- 5:30pm R ED2025 LAB 10:10am- 12:05pm F LH025 LAB 12:20pm- 2:15pm F LH025