Week 1 Tasks

Java Development Kit (JDK) installation and set up

  1. Make sure you have JDK (Java SE) installed in your system. Go to java.sun.com or get an installer from the DISCS technical staff (F225).
  2. Set some environment variables so that you could compile and execute Java programs on the command line. Refer to the following screenshots: JDKSetup.doc . Take note of the JDK version and use the appropriate path when setting the environment variables; e.g., you may need to indicate "jdk1.6.0_04" instead of "jdk1.6.0_01".
  3. In addition, for tomcat-servlet functionality to be enabled, you will need to arrange it so that your CLASSPATH environment variable includes
    "C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;."
  4. Through the CMD prompt, you may compile a Java program by issuing the command: javac [ProgramName].java . You will need to be in the folder where the program resides. The following command tool script will be useful in this case (after the script is installed; right-click on the folder and issue the command prompt accordingly).

JDBC Overview: Connecting to a database through a Java program

  1. Create a Microsoft Access Database called phonebook.mdb with one database table called PHONENUM.
    Arrange it so that this table has columns named NAME and MOBILENUM (both of type text).
    Add a few rows to this table (e.g., name JOHN with mobile number 09185551234 and name MARY with mobile number 09175550000).
  2. Execute the following queries on the database:
  3. Register this database as an ODBC data source (Control Panel -> Admin Tools -> Data Sources (ODBC)). Important: Register it a System DSN, not a User DSN.
  4. Create a Java program that performs a query on the database. You could use the following sample code for a Java program called Select.java.

Servlet Overview: Web pages and Java servlets

  1. Install apache-tomcat in your machine. If your installation was correct, the following link: http://localhost:8080 should display the default tomcat webpage.
  2. Create a simple html web page. For example, you may create a file called sample.html with the following contents.
    Place the html file inside the webapps/ROOT folder and try opening the following URL: http://localhost:8080/sample.html.
  3. Create a web page with a form. For example, you may create a file called myform.html with the following contents.
    Place the html file inside the webapps/ROOT folder and try opening the following URL: http://localhost:8080/myform.html.
    When you click on the form button, it will open the sample.html form you made earlier.
  4. (Optional) Redirecting to google. In myform.html , replace "/sample.html" with "http://www.google.com/search", and replace "firstname" with "q".
    This will enable google searches from your page.
  5. Create a Java servlet. Here is a Sample Servlet ; It should be defined in a file named WelcomeServlet.java.
  6. Now here's the most complex part: you will assemble a web application. First, create another form called myotherform.html with the following contents.
  7. Create a folder called mywebapp .
    That folder should contain myotherform.html and a folder called WEB-INF .
  8. Inside the WEB-INF folder, create a classes folder. Inside the classes folder, create a servlets folder.
    Inside the servlets folder, place the compiled Java program WelcomeServlet.java. (Actually, what needs to be in that folder is the WelcomeServlet.class file).
  9. Create a web.xml file with the following contents. Place the web.xml file inside the WEB-INF folder.
  10. Place the entire mywebapp directory structure inside the tomcat webapps folder.
    If you carried out each step properly, the following link: http://localhost:8080/mywebapp/myotherform.html
    should demonstrate a working web application. Here's a zip file containing the entire directory structure, if you want a short cut :-).