Follow these steps to get and install JSDK2.0
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.
uncompress jsdk20-solaris2-sparc_tar.Z
This creates: jsdk20-solaris2-sparc_tar
This creates atar xvf jsdk20-solaris2-sparc_tar
JSDK2.0
directory. 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:
bin/servletrunner
-- this is the ServletRunner (a simple web server
that supports servlets and only servlets)
doc
-- tutorial and API documentation.
examples
-- example servlets.
servletrunner
please
/u/username/JSDK2.0/examples
where../bin/servletrunner -p 2980x
username
is your username
2980x
is your other port
At this point thetucotuco.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
servletrunner
is running with JVM too. On the client side (your LH115 machine) open up Netscape and connect to
and you should see the output of SimpleServlet.http://YourBurrowHost.cs.indiana.edu:2980x/servlet/SimpleServlet
A the same time serverrunner
will print a line like this to
acknowledge the servlet is initialized.
TypeSimpleServlet: init
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
.
Now we need to compile it.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%
First, lets unjar
the necessary classes:
Then we set thetucotuco.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) ...
CLASSPATH
variable and compile.
We need to modify... (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%
servlet.properties
and then we can test
MyServlet
from Netscape.
Now we simply start thetucotuco.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%
servletrunner
as we did before and
connect to host:2980x/servlet/MyServlet
On the server side we stop thetucotuco.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%
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: