|
Fall Semester 2004 |
Sat-Tue Dec 11-14
<% int count, right; String message = "Hello and welcome to the addition quiz!";
if (session.getAttribute("count") == null || request.getParameter("reset") != null) {
session.setAttribute("count", new Integer(0)); count = 0;
session.setAttribute("right", new Integer(0)); right = 0;
} else {
count = ((Integer)(session.getAttribute("count"))).intValue();
right = ((Integer)(session.getAttribute("right"))).intValue();
try {
if (Integer.parseInt(request.getParameter("answer")) == ((Integer)(session.getAttribute("answerKey"))).intValue())
right += 1;
else
right += 0;
} catch (Exception e) { }
count += 1;
message = right + " out of " + count;
if (count == 10) {
message = "Final result: " + message + ". New game started "; count = 0; right = 0;
} else
message = "Your performance thus far: " + message;
session.setAttribute("count", new Integer(count));
session.setAttribute("right", new Integer(right));
}
int one = (int) (Math.random() * 100 - 50),
two = (int) (Math.random() * 100 - 50);
session.setAttribute("answerKey", new Integer(one + two));
%>
<html>
<body>
<form action="<%=request.getContextPath() + request.getServletPath()%>">
<%=message%> <p>
Question <%=count+1%>. <%=one%> + <%=two%> = <input type="text" name="answer"> <p>
<input type="submit" value="Proceed"> <input type="submit" name="reset" value="Reset"> <p>
</form>
</body>
</html>
It is clean and compact, and a pleasure to study (I hope).
Fri Dec 10import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import ____.___._;
public class Three extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException,
IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println(" Hello here are the answers. <p> ");
___ _{
_____._______("___.___.__._____.______");
} _____ (_________ _) {
______.___._______("______________________. ______________________________.");
}
___________________________________________
_________________,
___________________;
_____________________;
_____
_________________________________________________________________;
__________________________________________________;
________________;
___________________________________;
_______________________________(
"__________________________________________" +
"_________________________________________"
);
_____________________ {
out.println(_________________________ +
____ + ___________________);
}
_________________;
__________________;
} ______________________ {
_________________________________________________________________;
} ___________________ {
_____________________________________;
}
}
}
Tue-Thu Dec 7-9
Sat-Mon Dec 4-6
Wed-Fri Dec 1-3Final exam is on
7:15-9:15 p.m., Wed., December 15Please refer to the Registrar's Final Exam Schedule for more details.
Starting today:
The very popular CATCH UP DAYS are finally here!
Tue Nov 30Tonight: applet to servlet communication, and JDBC.
Mon Nov 29Please consider why the call looks like this:
Note that a call tohttp://burrowww.cs.indiana.edu:9810/hw67/servlet/Exam?guess=eve&bet=40
after the program is started would break it:http://burrowww.cs.indiana.edu:9810/hw67/servlet/Exam
java.lang.NullPointerException, or
java.lang.NumberFormatException: null.
Do you know why?
You should.
(Just to make sure that a full blown example of translation is available to you.)
Wed-Sun Nov 24-28
HAPPY THANKSGIVING!
Tue Nov 23______ _____._______.*;
______ _____._______.____.*;
______ ____.__.*;
______ _____ Three _______ ___________ _
______ ____ _____(__________________ _______,
___________________ ________) ______ ________________,
___________ {
________.______________("_________");
___________ ___ = ________._________();
HttpSession session = request.getSession();
______ ____ = _______.______________() + _______.______________(),
_______ = (String) session.get_________("_______"),
_______________ = (String) _______.getAttribute("_________"),
________________ = (______) session.getAttribute("__________"),
_______________ = (String) session.___Attribute("_________");
String__ _____ = {"Paper", "Rock", "________"};
__ (_______ != ____) {
______ __________ = _______.____________("____");
___ ____ = _______.________(__________);
___ _________ = _______.________(_______________);
___ __________ = _______.________(________________);
___ _________ = _______.________(_______________);
__ ((____ + 1) % 3 == __________) {
_______ = "___ ___.";
_________ += 1;
} ____ __ ((__________ + 1) % 3 == ____) {
_______ = "___ ____.";
_________ += 1;
} ____ {
_______ = "____ __ _ ___.";
}
__________ = (___)(____.______() * 3);
________________ = __________ + "";
_______________ = _________ + "";
_______________ = _________ + "";
} ____ {
_______ = "_______.";
_______________ = "_";
_______________ = "_";
________________ = "" + (___)(____.______() * 3);
}
// save the _____ (you guessed it)
_______.setAttribute("compScore", comp___________);
session.___Attribute("message", _______);
session.setAttribute("_________", userScore______);
session.set_________("comp______", compChoiceString);
___._______(
"<____ ______=GET ______=" + name + ">" +
_______ +
" ___ ________ ___ ______: " +
names[Integer.parseInt(compChoiceString)] +
", ___ __'_ ____ ____. <_> " +
" <_____ ______><__><__> ________ <__> ____ " +
" <__><__>" + _______________ + "<__> " + _______________ + "</_____> <_> " +
" ____: <______ ____=\"____\">" +
" <______ _____=\"_\"> _____ " +
" <______ _____=\"_\"> ____ " +
" <______ _____=\"_\"> ________ " +
" </______> <_> " +
" ____ ________ ______ _____ <_____ ____=\"______\" _____=\"_______\"> <_> " +
" " +
" </____> "
);
}
}
(Needless to say the JSP is immediate).
Mon Nov 22He might be coming for 5-10 min. more to class tomorrow, Tuesday, Nov 23.
Fri-Sun Nov 19-211,8c1,2
< 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 {
---
> <%
>
12c6,8
< PrintWriter out = response.getWriter();
---
>
> // PrintWriter out = response.getWriter();
>
51,70c47
< out.println(
< "<form method=GET action=" + name + ">" +
< message +
< " The computer has chosen: " +
< names[Integer.parseInt(compChoiceString)] + ", now it's your turn. <p> " +
< " <table border><tr><td> Computer <td> User " +
< " <tr><td>" + compScoreString + "<td> " + userScoreString + "</table> <p> " +
< " What: <select name=\"user\">" +
< " <option value=\"0\"> Paper " +
< " <option value=\"1\"> Rock " +
< " <option value=\"2\"> Scissors " +
< " </select> <p> " +
< " When finished please press <input type=\"submit\" value=\"Proceed\"> <p> " +
< " <input type=\"hidden\" name=\"compScore\" value=\"" + compScoreString + "\"> " +
< " <input type=\"hidden\" name=\"message\" value=\"" + message + "\"> " +
< " <input type=\"hidden\" name=\"userScore\" value=\"" + userScoreString + "\"> " +
< " <input type=\"hidden\" name=\"compChoice\" value=\"" + compChoiceString + "\"> " +
< " " +
< " </form> "
< );
---
> %>
72c49,65
< }
---
> <form method=GET action=<%=name%>>
> <%=message%>
> The computer has chosen:
> <%=names[Integer.parseInt(compChoiceString)]%>, now it's your turn. <p>
> <table border><tr><td> Computer <td> User
> <tr><td><%=compScoreString%><td><%=userScoreString%></table> <p>
> What: <select name="user">
> <option value="0"> Paper
> <option value="1"> Rock
> <option value="2"> Scissors
> </select> <p>
> When finished please press <input type="submit" value="Proceed"> <p>
> <input type="hidden" name="compScore" value="<%=compScoreString%>">
> <input type="hidden" name="message" value="<%=message%>">
> <input type="hidden" name="userScore" value="<%=userScoreString%>">
> <input type="hidden" name="compChoice" value="<%=compChoiceString%>">
> </form>
74d66
< }
Thu Nov 18import javax.servlet.*;
import javax._______.http.*;
import java.__.*;
public class ___ extends ____Servlet {
public void do___(Http_______Request request,
HttpServlet________ response) ______ ServletException,
__Exception {
response.set_______Type("text/html");
___________ out = response.getWriter();
String ____ = request.getContextPath() + request.getServletPath(),
message = request.getParameter("message"),
compScoreString = request.get_________("compScore"),
compChoiceString = _______.getParameter("compChoice"),
userScoreString = request.getParameter("userScore");
if (message != ____) {
______ userString = request.getParameter("____");
int user = Integer.parseInt(__________);
int comp_____ = Integer.parseInt(compScoreString);
int comp______ = Integer.parseInt(compChoiceString);
int userScore = Integer.parseInt(userScoreString);
if ((user + 1) % 3 == __________) {
message = "You won.";
____Score += 1;
} else if ((compChoice + 1) % 3 == ____) {
message = "You lose.";
____Score += 1;
} else {
message = "____ __ _ ____";
}
compChoice = (int)(Math.random() * 3);
compChoice______ = compChoice + "";
____ScoreString = compScore + "";
____ScoreString = userScore + "";
} else {
_______ = "Welcome.";
compScoreString = ___;
userScoreString = ___;
compChoiceString = __ + (int)(Math.random() * 3);
}
out.println(
"<form ______=GET ______=" + name + ">" +
message +
" The computer has chosen: " + compChoice______ + ", now it's your turn. <p> " +
" <table border><tr><td> Computer <td> User " +
" <tr><td>" + compScore______ + "<td> " + userScore______ + "</table> <p> " +
" What: <______ name=\"user\">" +
" <option value=\"_\"> Paper " +
" <option value=\"1\"> ____ " +
" <option value=\"2\"> Scissors " +
" </select> <p> " +
" When finished please press <input type=\"submit\" value=\"Proceed\"> <p> " +
" <input type=\"______\" name=\"compScore\" value=\"" + compScore______ + "\"> " +
" <input type=\"hidden\" name=\"_______\" value=\"" + message + "\"> " +
" <input type=\"hidden\" name=\"userScore\" value=\"" + userScore______ + "\"> " +
" <input type=\"hidden\" name=\"compChoice\" value=\"" + compChoice______ + "\"> " +
" " +
" </form> "
);
}
}
Wed Nov 17
Sat-Tue Nov 13-16to clearly identify your What's New? portion of the website.
(Note that clicking on it takes it to the sample what's new I set up on the demo server).
Thu-Fri Nov 11-12
|
Installing Tomcat_5.0.27 is easy:
I will create more links to more concrete examples here but this is all there is to it! |
Mon-Wed Nov 8-10
Fri-Sun Nov 5-7<html>
<script>
c_choice = Math.round(Math.random() * 2);
names = new Array("Paper", "Rock", "Scissors");
function process() {
alert("User has selected: " + document.forms[0].u_choice.options[document.forms[0].u_choice.selectedIndex].value);
c_choice = Math.round(Math.random() * 2);
document.getElementById("c_choice").innerHTML = names[c_choice];
}
</script>
<body>
Computer has chosen: <span id="c_choice"></span> <p>
<script>
document.getElementById("c_choice").innerHTML = names[c_choice];
</script>
<form>
User chooses: <select name="u_choice">
<option value="Paper"> Paper
<option value="Rock"> Rock
<option value="Scissors"> Scissors
</select>
<p> Then the user presses <input type="button"
value="Submit"
onClick="process()">
</form>
</body>
</html>
Thu Nov 4
Mon-Wed Nov 1-3Here's the code you need for your Lab Eight work:
<?
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);
}
}
?>
The only question now is, where do you place it?
Sat-Sun Oct 30-31Code needed for Lab Eight to be posted soon.
Fri Oct 29
Thu Oct 28#!/usr/bin/perl
use CGI;
use ___;
use MD5;
$DB = "DBI:_____:a348";
$________ = "a348";
$password = "______";
$DB_TABLE = "___________";
$SECRET = "something secret";
_______ = 30 * 60 * 60 * 24; # one month
$MAX_TRIES = 10;
$ID_LENGTH = _;
__ = new CGI;
$DBH = DBI->_______($DB, $username, $password, { PrintError => 0 })
|| die "Couldn't open database: ", $DBI::errstr;
my ($session_id) = &get_session_id();
print $q->______, $q->start_html;
my $state = &get_state(___________);
if (! $state->{message}) {
$state = &__________($state);
} else {
$number = $q->param('number');
$_____ = &calculate(______, _______);
}
&save_state($state, $session_id);
&report($state);
&show_form(); # get ready for more input
print $q->end_html;
sub ______________ {
&expire_old_sessions();
my ($id) = $q->path_info =~ m:^/([a-h0-9]{$ID_LENGTH}):o;
return $id if $id and &check_id($id);
my $session_id = &generate_id;
die "Couldn't make a new session_id" unless $session_id;
print $q->________($q->script_name() . "/$session_id");
exit(0);
}
sub ___________________ {
$DBH->do(<<END);
DELETE FROM $DB_TABLE
WHERE (unix_timestamp() - unix_timestamp(modified)) > $EXPIRE
END
}
sub ___________ {
my $tries = 0;
my $id = &hash($SECRET . rand());
while ($tries++ < __________) {
last if
$DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");
$id = &hash($SECRET . rand());
}
return undef if $tries >= $MAX_TRIES;
return $id;
}
sub hash {
my $value = shift;
return substr(MD5->hexhash($value), 0, $ID_LENGTH);
}
sub ________ {
my $id = shift;
return $id
if $DBH->do("SELECT 1 FROM $DB_TABLE WHERE session_id = '$id'") > 0;
return $id
if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");
return '';
}
sub show_form {
print $q->start_form(), qq{
______ _____ ____ ______: _________________________________ <p> },
"When done please press ",
$q->submit(-value=>'Proceed'),
$q->end_form();
}
sub _________ {
my $id = shift;
my $query = "SELECT * FROM _________ 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;
}
sub _________ {
my $state = shift; # first param
my $number = shift; # second param
my $balance = $state->{_______};
my $_______ = $state->{mess___};
if ($number > 0 && $number < 11) {
$balance += $number;
if ($balance >= 100) {
$message = "Congratulations, you ____\n";
$balance = 0;
$message .= "The current balance is $balance.\n";
} else {
$computer = int(rand(10)) + 1;
________________________________________________
$balance += $computer;
if ($balance >= 100) {
$message .= "The computer just won the game.\n";
_____________
$message .= "The current balance is $balance.\n";
} else {
$message .= "The current balance is $balance.\n";
}
}
} else {
$message = "Sorry, you lost.\n";
____________;
$message .= "The current balance is $balance.\n";
}
$state->{_______} = $balance;
$state->{message} = ________;
return $state;
}
sub __________ {
my ($state, $id) = @_;
my $sth = $DBH->prepare(<<END) || die "Prepare: ", $DBH->errstr;
UPDATE $DB_TABLE
SET _______ = ?, _______ = ?
WHERE session_id = '$id'
END
$sth->execute(@{$state}{qw(balance message)})
|| die "Execute: ", $DBH->errstr;
$sth->finish;
}
sub ______ {
my ($state) = @_;
print qq{
_______: $state->{balance} <p>
Message: $_____->{message} <p>
}; # note that computer choice printed is just a number
}
sub initialize {
my $state = shift;
$state = {} unless $state;
$state->{_______} = 0;
$________message_ = "_______. The current balance is: ". $state->{balance};
return $state;
}
Wed Oct 27
Thu-Tue Oct 21-26#!/usr/bin/perl
while (true) {
if ($message) {
$number = <STDIN>;
if ($number > 0 && $number < 11) {
$balance += $number;
if ($balance >= 100) {
$message = "Congratulations, you won.\n";
$balance = 0;
$message .= "The current balance is $balance.\n";
} else {
$computer = int(rand(10)) + 1;
$message = "Computer has chosen... $computer\n";
$balance += $computer;
if ($balance >= 100) {
$message .= "The computer just won the game.\n";
$balance = 0;
$message .= "The current balance is $balance.\n";
} else {
$message .= "The current balance is $balance.\n";
}
}
} else {
$message = "Sorry, you lost.\n";
$balance = 0;
$message .= "The current balance is $balance.\n";
}
} else {
$message = "Welcome.\n";
$balance = 0;
$message .= "The current balance is $balance.\n";
}
print $message;
print "Please enter a new number: ";
}
print "Thanks for playing.";
# Example of running a session with this program:
#
# burrowww.cs.indiana.edu% ./demo
# Welcome.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 9
# The current balance is 19.
# Please enter a new number: 10
# Computer has chosen... 2
# The current balance is 31.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 51.
# Please enter a new number: 10
# Computer has chosen... 6
# The current balance is 67.
# Please enter a new number: 10
# Computer has chosen... 7
# The current balance is 84.
# Please enter a new number: 10
# Computer has chosen... 6
# The computer just won the game.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 1
# The current balance is 11.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 31.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 51.
# Please enter a new number: 3
# Computer has chosen... 7
# The current balance is 61.
# Please enter a new number: 10
# Computer has chosen... 10
# The current balance is 81.
# Please enter a new number: 8
# Computer has chosen... 2
# The current balance is 91.
# Please enter a new number: 10
# Congratulations, you won.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 7
# The current balance is 17.
# Please enter a new number: -3
# Sorry, you lost.
# The current balance is 0.
# Please enter a new number: 10
# Computer has chosen... 7
# The current balance is 17.
# Please enter a new number: 11
# Sorry, you lost.
# The current balance is 0.
# Please enter a new number:
#
Wed Oct 20Date: Wed, 20 Oct 2004 15:47:07 -0500 (EST) From: Adrian German <dgerman@cs.indiana.edu> To: A348/A548 Fall 2004 Distr. List <dgerman@indiana.edu> Subject: Labs today and tomorrow and the Midterm Exam Dear A348/A548 friends, Thu and Fri I am in Savannah, GA, for a presentation to a conference (FIE 2004). http://fie.engrng.pitt.edu/fie2004/index.htm (under Authors) would give you my paper (German, Dan-Adrian). We'll cover the paper in class at some point in November. The exam is proctored by Pavel Anaschenko. It's on Thu 5:30pm in class. The exam is open-book. Labs today and tomorrow should be used to eliminate all questions about Homework 2 and 4, Lab 7 and the Sample Midterm posted. Please review the template posted under What's New? Wed-Thu Sep 15-16. It should help you approach the problems uniformly. For the exam tomorrow the technology of your choice is required: PHP or CGI with or without sessions. For Tue please post all four implementations. CGI/DBI implementation of the problem you will receive for the exam tomorrow will be discussed in class on Tue so, as far as that implementation goes, significant help will be offered then. All four implementations are due on your web sites by Tue end of day, source code included. If you have questions or concerns please let me know. Good luck with your exam tomorrow. ... Adrian
Fri-Sun Oct 15-17
This should come in handy for Tuesday's class.
Thu Oct 14
Grading in progress.
Mon-Wed Oct 11-13<? session_start(); ?>
<____><____><_____>________ ____ ____ Two (using sessions)</_____></____><____>
<?
__ (________) _
if ($age == $ageCopy) {
$age += 1;
__ ((_________) _ _ __ ___________) {
________ _ ___________
__________ __ __
_ ____ __ ((___________ _ _) _ _ __ _____) {
________ _ ____________
__________ __ __
_ ____ _
________ _ _________________
_
___________ _ ___________
} else {
$message = "You can't reload. ";
}
_ ____ _
session_register("message");
session_register("age");
session_register("compScore");
session_register("userScore");
session_register("compChoice");
$message = "Welcome.";
$compScore = 0;
$userScore = 0;
$compChoice = rand(0, 2) ;
$age = 0;
_
__
<____>
<? ____ _________ ?> <_>
___ ________ ___ ______: <?=___________?>, ___ __'_ ____ ____. <_>
<_____ ______><__><__> ________ <__> ____
<__><__> <?=__________?> <__> <?=__________?> </_____> <_>
____: <______ ____=______>
<______ _____=___> _____
<______ _____=___> ____
<______ _____=___> ________
</______> <_>
____ ________ ______ _____ <_____ ____="______" _____="_______"> <_>
<input type="hidden" name="ageCopy" value="<?=$age?>">
</____> </____></____>
Sat-Sun Oct 9-10<html><head><title>Homework ____ Part One (______ ______)</title></head><____>
__
__ ($mess___) {
if (($____ + _) % 3 == $c____hoice) {
$mess___ = "You ____";
$us___core __ 1;
} ____ if (($c____hoice + 1) _ 3 == $_____ {
$mess___ = "You _____";
$____Score += 1;
} else _
$____age = "This is a ____";
}
$c hoice = _and(0, 2) ;
_ ____ _
$mess___ = "________";
$c_____ore = _;
$us___core = 0_
$c____hoice = ____(0, 2) ;
}
__
<____>
<? ___o $message; ?> <p>
The computer has chosen: ___$c____hoice?>, now it's your ____. <p>
<_____ border><tr><td> Computer <td> User
<tr><td> <?=$compScore?> <td> <?=$us___core?> </table> <p>
What: <______ name="user">
<option value=___> Paper
<option _____="1"> ____
<______ value="_"> Scissors
</select> <p>
When finished please press <input type="submit" value="_______"> <p>
<input type="____en" name="_____core_ ___________________core_>">
<input type="hidden" name="mess___" value="__=$message?>">
<_____ type="hidden" name="us___core" value="___$user__ore?>">
<input type="hidden" name="c____hoice" value="____compChoice?>">
</form> </body></____>
Fri Oct 8Date: Thu, 7 Oct 2004 16:39:40 -0500 (EST)
From: Adrian German <dgerman@cs.indiana.edu>
To: A348/A548 Fall 2004 Distr. List <dgerman@indiana.edu>
Subject: A348/A548 update
Dear A348/A548 friends,
The priority this week would be to install PHP properly. That means you
should do it on /nobackup have your own ~/apache/apache_1.3.26/phpsessions
at the end and making sure register_globals is On.
With this behind us we need to finish Homework Four right away.
For next week please make individual appointments through the script that
has been posted on What's New? under Thu Oct 7 or directly at:
http://burrowww.cs.indiana.edu:9760/cgi-bin/fall2004/schedule
Just choose a time and type your username then click Proceed.
Please let me know if you have any questions and/or if you need any help.
... Adrian
Reminder that PHP to be installed is located (and can be found in):
One extra change needs to be made tofrilled.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%
php.ini:
But we also need to be aware of potential security problems as well.register_globals = On
Thu Oct 7
Script for individual appointments next week.
Wed Oct 6 | | ||
| Thanks to | Mike Sassman and | Adrian Padilla | for suggesting the example below: |
#!/usr/bin/perl
use CGI;
$pda = new CGI;
print "Content-type: text/html\n\n";
if ( $pda->param('message') ) {
$userSelection = $pda->param('helicopter');
if ($userSelection == 0 && $pda->param('compChoice') == 0) {
print "Both have chosen paper: tie.";
} elsif ($userSelection == 0 && $pda->param('compChoice') == 1) {
print "User's paper beats computer's rock.";
} elsif ($userSelection == 0 && $pda->param('compChoice') == 2) {
print "User's paper loses to computer's scissors.";
} elsif ($userSelection == 1 && $pda->param('compChoice') == 0) {
print "User's rock second to computer's paper.";
} elsif ($userSelection == 1 && $pda->param('compChoice') == 1) {
print "Rock user rock computer tie.";
} elsif ($userSelection == 1 && $pda->param('compChoice') == 2) {
print "Computer scissors user rock user wins.";
} elsif ($userSelection == 2 && $pda->param('compChoice') == 0) {
print "Computer paper but user scissors wins.";
} elsif ($userSelection == 2 && $pda->param('compChoice') == 1) {
print "Paper computer, but user rock, loses.";
} elsif ($userSelection == 2 && $pda->param('compChoice') == 2) {
print "Scissors scissors tie.";
} else {
print "Boy, aren't you surprised to see this...?!";
}
} else {
$x = int(rand(3));
@choices = ("paper", "rock", "scissors");
print qq{
<form>
The computer has chosen: $choices[$x] ($x) <p>
It's your turn: <select name="helicopter">
<option value="0"> Paper
<option value="1"> Rock
<option value="2"> Scissors
</select> <p>
Then push <input type="submit" value="Proceed">
<input type="hidden" name="compChoice" value="$x">
<input type="hidden" name="message" value="Existing user.">
</form>
};
}
Sat-Tue Oct 2-5You should start working on Homework Four now (same program from Homework Two).
For the following assignments you need to work the same program as for Homework Four only using:
Sun-Fri Sep 26-Oct 1As far as the extra space needed the information is here.frilled.cs.indiana.edu%pwd /nfs/grouchy/san/r1a0l7/www/classes/a348-dger/software/php frilled.cs.indiana.edu%ls -l total 4728 -rw-r--r-- 1 dgerman faculty 4832738 Jun 14 00:19 php-4.3.7.tar.gz frilled.cs.indiana.edu%
Fri-Sat Sep 24-25#!/usr/bin/perl
print qq{Content-type: text/html\n\n};
$in = $ENV{QUERY_STRING};
@pairs = split(/&/, $in);
foreach $pair (@pairs) {
($nam, $val) = split(/=/, $pair);
$in{$nam} = $val;
}
# foreach $k (keys %in){
# print $k, " --> ", $in{$k}, "<p>";
# }
$balance = $in{balance};
if ($in{fun} eq "add") { $balance += $in{arg}; }
elsif ($in{fun} eq "sub") { $balance -= $in{arg}; }
else { $balance += 0; }
print qq{
<form method=GET action=$ENV{SCRIPT_NAME}>
Balance: $balance <p>
What: <select name="fun">
<option value="non"> Click me!
<option value="add"> Deposit
<option value="sub"> Withdraw
</select> <p>
Amount: <input type="text" name="arg"> <p>
When finished please press <input type="submit" value="Proceed"> <p>
<input type="text" name="balance" value="$balance">
</form>
};
The calculator above is yours without any limiting conditions. Parts of the one below have been obscured, though, to not limit any participation on your part:
#!/usr/bin/perl
# state is ________ of:
# $mess___
# $____Score
# $user_____
# $comp______
# _____ is provided by the:
# $user
print qq{Content-type: ____/____\n\n};
$in = $ENV{____________}; # what if it's POST?
@_____ = split(/&/, $in);
foreach $____ (@pairs) {
($nam, $___) = split(/=/, $pair);
$in{$___} = $val;
}
# foreach $k (keys %in){
# print $k, " --> ", $in{$k}, "<p>";
# }
$message = $in{message};
$compScore = ______________;
$userScore = $in{userScore};
$__________ = $in{compChoice};
if (________) {
$user = $__{user};
if (($user + 1) % 3 == $compChoice) {
$message = "________";
$_________ += 1;
} elsif (($__________ + 1) % 3 == $user) {
$message = "You lose.";
$compScore __ _;
} else {
$message = "This is a tie.";
}
$compChoice = ____________;
} else {
$_______ = "Welcome.";
$compScore = 0;
$userScore = 0;
$compChoice = ___(rand(3));
}
print qq{
<form method=GET action=_________________>
$message <p>
The computer has chosen: $compChoice, now it's your ____. <p>
<table border><tr><td> ________ <td> User
<tr><td> $compScore <td> $userScore </table> <p>
What: <select name="user">
<option value="0"> _____
<option value=___> Rock
<______ value="2"> Scissors
</select> <p>
When finished please press <input type="submit" value="Proceed"> <p>
<_____ type="hidden" name="compScore" value="$compScore">
<input type="______" name="_______" value="$message">
<input type="hidden" name="userScore" value="__________">
<input type="hidden" ____="compChoice" value="$compChoice">
</form>
};
Thu Sep 23
sees it:
... both courtesy of Brandon McGhan (Spring 2003 A348/A548 student).
Grades will be updated (very late) tonight.
Wed Sep 22#!/usr/bin/perl
print "Content-type: text/html\n\n";
print qq{<html><head><title>Homework Two</title></head><body>};
print $ENV{QUERY_STRING}, "<p>";
if ($ENV{REQUEST_METHOD} eq "POST") {
read(STDIN, $input, $ENV{CONTENT_LENGTH});
} else {
$input = $ENV{QUERY_STRING};
}
$input =~ s/\+/ /g;
@pairs = split(/&/, $input);
foreach $pair (@pairs) {
# print $pair, "<p>";
($nam, $val) = split(/=/, $pair);
$nam =~ s/%(..)/chr(hex($1))/ge;
$val =~ s/%(..)/chr(hex($1))/ge;
print $nam, " goes with ", $val, "<p>";
}
print qq{
<form method=POST action="$ENV{SCRIPT_NAME}">
Username: <input type="text" name="uname" size=8> <p>
Password: <input type="password" name="pword" size=14> <p>
When done please press <input type="submit" value="proceed">
</form>
};
print qq{</body></html>};
Tue Sep 21#!/usr/bin/perl
print "Content-type: text/html\n\n";
foreach $k (keys %ENV) {
if ($k eq $ENV{QUERY_STRING}) {
print $k, " --> ", $ENV{$k}, "<br>\n";
} else {
print "<a href=\"",$ENV{SCRIPT_NAME},"?$k\">$k</a> <br>\n";
}
}
Sun-Mon Sep 19-20The necessary info is somewhere on that page.http://kb.indiana.edu/data/aelc.html
Fri-Sat Sep 17-18burrowww.cs.indiana.edu% crontab -l 0 * * * * /u/dgerman/apache/apache_1.3.26/bin/apachectl restart > /dev/null burrowww.cs.indiana.edu%The entry above works (for me) and does not send e-mail.
Wed-Thu Sep 15-16
Sat-Tue Sep 11-14
|
|
|
| Chris O'Brien | Soren Packer | Ronald Smith |
Fri Sep 10Don't forget to move the file there, first (fromburrowww.cs.indiana.edu% chmod 711 ~ burrowww.cs.indiana.edu% chmod 755 ~/public burrowww.cs.indiana.edu% chmod 644 ~/public/whoa.tar.gz
lab1).
Thu Sep 9#!/usr/bin/perl
$username = $ARGV[0];
if ($username eq "") { `yes | rm -ir wh* exp* `; print `ls -ld * `; exit; }
`cp /u/$username/public/whoa.tar.gz . `;
`gunzip whoa.tar.gz`;
`tar xvf whoa.tar`;
print `du -a exp*`;
print `more exp*/doc*/doc?.txt`;
print "Should I delete it? ";
$answer = <STDIN>;
chop($answer);
if ($answer eq "yes") {
`yes | rm -ir wh* exp* ` ; print ` ls -ld * `;
}
Wed Sep 8
Mon Sep 6
Mon-Fri Aug 31-Sep 3
A348/A548