1. Getting and Installing JSDK2.0

Follow these steps to get and install JSDK2.0

  1. Go to the root of your home directory (type cd) and copy the compressed archive from the public repository for this lab to your home directory:

    cp /u/dgerman/jsdk/jsdk20-solaris2-sparc_tar.Z .

    Note: you can also download this file directly from Sun if you prefer.

  2. Uncompress the archive by running:

    uncompress jsdk20-solaris2-sparc_tar.Z

    This creates: jsdk20-solaris2-sparc_tar

  3. Unarchive the file by running:
    tar xvf jsdk20-solaris2-sparc_tar
    This creates a JSDK2.0 directory.
  4. You can now remove jsdk20-solaris2-sparc_tar.

    2. Working with servletrunner

    There's a README file in your JSDK2.0 directory. Please refer to it for more detailed information, although for the purpose of this lab the notes presented here are complete.

    The JSDK serves as a reference implementation for the Java Servlet API. The release that you have installed works on top of JDK1.1, if you're interested in developing servlets with JDK1.2 there is no need to use this JSDK since the servlet API is bundled with JDK1.2.

    Your JSDK directory will have:

    To start your servletrunner please
    1. make sure you're logged into your host

    2. move to /u/username/JSDK2.0/examples

    3. then type
      ../bin/servletrunner -p 2980x 
      where

      • username is your username

      • 2980x is your other port

    You should see something similar to this:
    tucotuco.cs.indiana.edu% pwd
    /nfs/paca/home/user2/dgerman/JSDK2.0/examples
    tucotuco.cs.indiana.edu% ../bin/servletrunner -p 29800 
    servletrunner starting with settings:
      port = 29800
      backlog = 50
      max handlers = 100
      timeout = 5000
      servlet dir = ./examples
      document dir = ./examples
      servlet propfile = ./examples/servlet.properties
    
    
    At this point the servletrunner is running with JVM too.

    On the client side (your LH115 machine) open up Netscape and connect to

    http://YourBurrowHost.cs.indiana.edu:2980x/servlet/SimpleServlet
    and you should see the output of SimpleServlet.

    A the same time serverrunner will print a line like this to acknowledge the servlet is initialized.

    SimpleServlet: init
    Type Control-C to stop the servletrunner and let's move to the next section.

    3. Writing Servlets

    You're ready to write your own servlets. Let's do it slowly, and we will start by modifying the code from SimpleServlet.

    tucotuco.cs.indiana.edu% pwd
    /nfs/paca/home/user2/dgerman/JSDK2.0/examples
    tucotuco.cs.indiana.edu% cp SimpleServlet.java MyServlet.java tucotuco.cs.indiana.edu% ls -l MyServlet.java -r--r--r-- 1 dgerman students 1938 Nov 17 01:17 MyServlet.java tucotuco.cs.indiana.edu% chmod 644 MyServlet.java tucotuco.cs.indiana.edu% vi MyServlet.java tucotuco.cs.indiana.edu% diff SimpleServlet.java MyServlet.java
    32c32 < public class SimpleServlet extends HttpServlet --- > public class MyServlet extends HttpServlet 45c45 < String title = "Simple Servlet Output"; --- > String title = "My Servlet Works"; 57c57 < out.println("<P>This is output from SimpleServlet."); --- > out.println("<P>Welcome to the carousel!"); tucotuco.cs.indiana.edu%
    Now we need to compile it.

    First, lets unjar the necessary classes:

    tucotuco.cs.indiana.edu% pwd
    /nfs/paca/home/user2/dgerman/JSDK2.0/examples
    tucotuco.cs.indiana.edu% cd ../lib
    tucotuco.cs.indiana.edu% ls
    jsdk.jar
    tucotuco.cs.indiana.edu% jar xvf *
    created: javax/ created: javax/servlet/ created: javax/servlet/http/ extracted: javax/servlet/http/HttpUtils.class extracted: javax/servlet/http/HttpServletRequest.class extracted: javax/servlet/http/Cookie.class ... (and so forth) ...
    Then we set the CLASSPATH variable and compile.
     ... (from above) ... 
     extracted: sun/servlet/http/HttpServletConfig.class
     extracted: sun/servlet/ServletConnection.class
     extracted: sun/servlet/ServletLoader.class
    tucotuco.cs.indiana.edu% pwd
    /nfs/paca/home/user2/dgerman/JSDK2.0/lib
    tucotuco.cs.indiana.edu% cd ../examples
    tucotuco.cs.indiana.edu% pwd
    /nfs/paca/home/user2/dgerman/JSDK2.0/examples
    tucotuco.cs.indiana.edu% setenv CLASSPATH /u/dgerman/JSDK2.0/lib
    tucotuco.cs.indiana.edu% echo $CLASSPATH /u/dgerman/JSDK2.0/lib tucotuco.cs.indiana.edu% ls -l MyServlet.java -rw-r--r-- 1 dgerman students 1919 Nov 17 01:18 MyServlet.java tucotuco.cs.indiana.edu% javac MyServlet.java tucotuco.cs.indiana.edu%
    We need to modify servlet.properties and then we can test MyServlet from Netscape.

    tucotuco.cs.indiana.edu% pwd
    /nfs/paca/home/user2/dgerman/JSDK2.0/examples
    tucotuco.cs.indiana.edu% ls -l servl*
    -r--r--r--   1 dgerman  students     526 Apr 21  1998 servlet.properties
    tucotuco.cs.indiana.edu% cp servlet.properties servlet.properties.backup
    tucotuco.cs.indiana.edu% chmod 644 servlet.properties
    tucotuco.cs.indiana.edu% vi servlet.properties
    tucotuco.cs.indiana.edu% diff servlet.properties servlet.properties.backup
    18,20d17 < # my servlet < servlet.myservlet.code=MyServlet <
    tucotuco.cs.indiana.edu%
    Now we simply start the servletrunner as we did before and connect to host:2980x/servlet/MyServlet
    tucotuco.cs.indiana.edu% pwd
    /nfs/paca/home/user2/dgerman/JSDK2.0/examples
    tucotuco.cs.indiana.edu% ../bin/servletrunner -p 29800
    servletrunner starting with settings:
      port = 29800
      backlog = 50
      max handlers = 100
      timeout = 5000
      servlet dir = ./examples
      document dir = ./examples
      servlet propfile = ./examples/servlet.properties
    MyServlet: init
    ^Ctucotuco.cs.indiana.edu% 
    
    On the server side we stop the servletrunner when the demo is concluded.

    4. Where Do We Go From Here?

    You are now ready to try more sophisticated examples described in the lecture or you can now pick up a book on this topic and start deepening your understanding of the subject. For example: