Welcome to the lab.

https://www.cs.indiana.edu/classes/c212-dgerman/sum2016/secure/bchgfn.pdf

public abstract class Bird {
  public abstract void fly();  
  public abstract void deepDive(); 
  public abstract void talk(); 
  public String toString() {
    this.fly(); 
    this.deepDive(); 
    this.talk(); 
    return " I'm a Bird. ";     
  }
}

public class Duck extends Bird {
  public void fly() { 
    System.out.println("I fly like a Duck."); 
  }  
  public void deepDive() { 
    System.out.println("I don't deep dive, I'm a Duck."); 
  } 
  public void talk() { 
    System.out.println("Ducks don't talk."); 
  } 
  public String toString() {
    super.toString(); 
    return " -- all of this comes from a Duck."; 
  }
}

public class Example {
  public static void main(String[] args) {
    Duck a = new Duck(); 
    System.out.println( a ); 
  }
}

Compile and run Example. 

Hopefully this helps with Homework 06 (exam material). 

Next we do Lab 10. 

 1. Log into silo. 

 2. Go to $CATALINA_HOME

 3. Go into webapps

 4. Create a squash folder and move into it. 

We essentially aim for this structure:

$CATALINA_HOME --+-- webapps --+-- squash --+-- WEB-INF --+-- classes --+-- One.java
                 |             |            |             |
                 |             |            |             +-- lib 
                 |             |            |             | 
                 |             |            |             +--- web.xml
                 |             |            |
                 |             |            +-- one.html
                 |             |            |
                 |             |            +-- index.html
                 |             | 
                 |             +-- ROOT --+-- WEB-INF ... 
                 +-- bin                  | 
                 |                        +-- index.html 
                 +-- conf                 
                 |                         
                 +-- logs
                 |
                 ... 

  5. Create a WEB-INF inside squash, then classes and lib folders inside WEB-INF:

[hashen@silo squash]$ pwd
/u/hashen/apache-tomcat-7.0.35/webapps/squash
[hashen@silo squash]$ mkdir WEB-INF
[hashen@silo squash]$ mkdir WEB-INF/classes
[hashen@silo squash]$ mkdir WEB-INF/lib
[hashen@silo squash]$ du -a .
4       ./WEB-INF/classes
4       ./WEB-INF/lib
12      ./WEB-INF
16      .
[hashen@silo squash]$

  6. Create a One.java file with this contents inside WEB-INF/classes

[hashen@silo squash]$ pwd
/u/hashen/apache-tomcat-7.0.35/webapps/squash
[hashen@silo squash]$ pico -w WEB-INF/classes/One.java
[hashen@silo squash]$ du -a .
4       ./WEB-INF/classes/One.java
8       ./WEB-INF/classes
4       ./WEB-INF/lib
16      ./WEB-INF
20      .
[hashen@silo squash]$ cd WEB-INF/
[hashen@silo WEB-INF]$ cd classes/
[hashen@silo classes]$ ls -l
total 4
-rw------- 1 hashen students 514 Jul 12 15:08 One.java
[hashen@silo classes]$ cat One.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class One extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response) throws IOException, ServletException {
    String name = request.getParameter("who");
    String age = request.getParameter("age");

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("Well, " + name + " you will be " + (age + 1) + " next year.");
  }
}
[hashen@silo classes]$

 7. Go into WEB-INF/classes and compile the One.java servlet. 

[hashen@silo classes]$ pwd
/u/hashen/apache-tomcat-7.0.35/webapps/squash/WEB-INF/classes
[hashen@silo classes]$ ls -l
total 4
-rw------- 1 hashen students 514 Jul 12 15:08 One.java
[hashen@silo classes]$ javac One.java
[hashen@silo classes]$ ls -l
total 8
-rw------- 1 hashen students 1074 Jul 12 15:10 One.class
-rw------- 1 hashen students  514 Jul 12 15:08 One.java
[hashen@silo classes]$

 8. Deploy the servlet. 

This means: go to WEB-INF and create web.xml with the following contents

[hashen@silo classes]$ pwd
/u/hashen/apache-tomcat-7.0.35/webapps/squash/WEB-INF/classes
[hashen@silo classes]$ cd ..
[hashen@silo WEB-INF]$ nano -w web.xml
[hashen@silo WEB-INF]$ ls -l
total 12
drwx------ 2 hashen students 4096 Jul 12 15:10 classes
drwx------ 2 hashen students 4096 Jul 12 15:06 lib
-rw------- 1 hashen students  431 Jul 12 15:12 web.xml
[hashen@silo WEB-INF]$ cat web.xml
<?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>radijs</servlet-name>
    <servlet-class>One</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>radijs</servlet-name>
    <url-pattern>/servlet/Radish</url-pattern>
  </servlet-mapping>

</web-app>
[hashen@silo WEB-INF]$

 9. Provide a minimal interface for the customer: 

[hashen@silo WEB-INF]$ pwd
/u/hashen/apache-tomcat-7.0.35/webapps/squash/WEB-INF
[hashen@silo WEB-INF]$ cd ..
[hashen@silo squash]$ ls -l
total 4
drwx------ 4 hashen students 4096 Jul 12 15:12 WEB-INF
[hashen@silo squash]$ pico -w index.html
[hashen@silo squash]$ ls -l
total 8
-rw------- 1 hashen students  513 Jul 12 15:14 index.html
drwx------ 4 hashen students 4096 Jul 12 15:12 WEB-INF
[hashen@silo squash]$ cat index.html
<html>
  <head>
    <title>
      My form on Tue 07/12/2016
    </title>
  </head>
  <body>

    <form action=/squash/servlet/Radish method=GET>

      <table border>
        <tr>
          <td> Name </td> <td> <input type=text name=who> </td>
        </tr>
        <tr>
          <td> Age </td> <td> <input type=text name=age> </td>
        </tr>
        <tr>
          <td colspan=2> Press <input type=submit value=Submit> to send data to servlet</td>
        </tr>
      </table>
    </form>
  </body>
</html>
[hashen@silo squash]$

10. Now go online and test it.

http://silo.cs.indiana.edu:60269/

For Mr. Jerry I also had to modify index as follows: 

[hashen@silo ROOT]$ pwd
/u/hashen/apache-tomcat-7.0.35/webapps/ROOT
[hashen@silo ROOT]$ ls -ld index.html
-rw------- 1 hashen students 234 Jul 12 15:16 index.html
[hashen@silo ROOT]$ cat index.html
My l<a href="/squash/">ink to Lab 1</a>0. <p>

Below is the picture you wanted: <p>

<img src="http://gallery.yopriceville.com/var/resizes/Free-Clipart-Pictures/Cartoons-PNG/Tom_and_Jerry_Free_PNG_Clip_Art_Image.png?m=1447961997">

[hashen@silo ROOT]$

--

Christian Kayl Levi Seth Jerry Haoxuan Shen Jared Alex S Vanessa Mike C Arif He He 
Keqin Max Yinan Joe B Andrew T Zhiwei Sunghyun Alex Q Xinyu Z Siddartha Xing Rerajitha 
Haoyuan Hu Matt Chenrui Rajeev Andrew R Brandon P David Lee Kevin S