You are on page 1of 4

Steps for Installing the Java Server Web Development Kit

1. Download: jswdk1_0_1-solsparc.tar.Z from: http://java.sun.com/products/servlet/archive.html This is the Solaris version of JavaServer Web Development Kit (JSWDK). 2. Extract the files (gunzip and tar). It will create a directory named jswdk-1.0.1 . (You can rename this directory) If you extracted the file in your home directory the directory structure would be like /HOME/jswdk-1.0.1 where HOME is the path to your home directory. 3. Go to the jswdk-1.0.1 directory. Here you will find a file webserver.xml which is the configuration file for the server. Open the file in an editor like pico and go to the lines <!ELEMENT Service (WebApplication*) <!ATTLIST Service id ID #REQUIRED port NMTOKEN "8080" <--------- change the "8080" port to one of your own (4 digit #, hostName NMTOKEN "" inet NMTOKEN "" 4. Save and exit from the editor. 5. The following archive files must be accessible to the javac compiler: webserver.jar , jspengine.jar, servlet.jar, xml.jar, and tool.jar. The file webserver.jar can be found in the jswdk-1.0.1 directory while the other three in the jswdk-1.0.1/lib directory. Also, it's good to define a JAVA_HOME environment variable. The JAVA_HOME and CLASSPATH lines in your .cshrc file should look something like: setenv JAVA_HOME /auto/usc/jdk/1.2.1 setenv CLASSPATH "/HOME/mm.mysql.jdbc-1.2c:/HOME/jswdk-1.0.1/webserver.jar:/HOME/jswdk-1.0.1/lib/servl et.jar:/HOME/jswdk-1.0.1/lib/xml.jar:/HOME/jswdk-1.0.1/lib/jspengine.jar:/usr/usc/jdk/1.2.1/li b/tools.jar:/HOME/jswdk-1.0.1/examples/WEB-INF/servlets" For your assignments, you will create a package that you will store in /HOME/jswdk-1.0.1/webpages/WEB-INF/servlets When you do that you will have to add the above path to the CLASSPATH. 6. Exit the editor and execute your .cshrc file by typing in 'source .cshrc' so that all the changes in the classpath environment take affect. 7. Go to the jswdk-1.0.1 directory and execute the startserver shell script by the following command: startserver The server will start, if you did everything right then there should be no error messages . The messages displayed would be something like : Using classpath: ./webserver.jar:./lib/jakarta.jar:./lib/servlet.jar:./lib/jsp.jar:./lib/jspengine.jar:./example s/WEB-INF/jsp/beans:./webpages/WEB-INF/jsp/beans:./webpages/WEBINF/servlets:./lib/xml.jar:/lib/tools.jar:/auto/homescf-12/your_username/mm.mysql.jdbc-1.2c:/auto/home-scf-12/your_username:/auto/homescf-12/your_username/jswdk/webserver.jar:/auto/homescf-12/your_username/jswdk/lib/servlet.jar different from your apache and mysql port #).

[1] Done startserver JSWDK WebServer Version 1.0.1 Loaded configuration from: file:/HOMEjswdk/webserver.xml endpoint created: localhost/127.0.0.1:8821 1. You can check if the server is running by opening the following link in a browser: http://csci571.usc.edu:PORT where PORT is the port number you had put in the webserver.xml file. (You might have to set the permissions in the webpages directory so that everyone has read access to index.html. chmod 755 *). You should get the JavaServer (tm) Web Development Kit home page. You can explore the servlet examples as you wish. 2. To stop the server, go to the jswdk-1.0.1 directory and execute: stopserver The server will stop, if you did everything right then there should be no error messages . IMPORTANT: If you recompile a servlet that you have tested in the server, you must STOP the server and START it AGAIN in order for the new servlet to take effect.

4. IMPORTANT: You must explore and learn the directory structure of the webserver.
jswdk-1 .0.1 /webpages /docs /api /WEBINF /servlets Sample URL

http://csci571.usc.edu:8821/ Store your project html pages here.

http://csci571.usc.edu:8821/docs/api/
Has servlets.properties file for /servlet directory underneath

http://csci571.usc.edu:8821/servlet/snoop Store your


project java server packages here.

/examples

http://csci571.usc.edu: 8821/examples/ThreeParamsForm.html
/images /jsp /servlets /WEBINF /servlets Only for servlet examples. Don't use Has servlets.properties file for /servlet directory underneath

http://csci571.usc.edu:8821/examples/servlet/dwHello

Note: The servlets in the directory /examples/WEB-INF/servlets/ are addressed in the URL as: http://csci571.usc.edu:8821/examples/servlet/servletname where /servlet/ in the path name has no s.

Create a subdirectory under: examples/WEB-INF/servlets/ for your files e.g. site_scripts etc Move the .html files to /examples Connect to: examples/WEB-INF/servlets/site_scripts or whatever you chose above. Create and compile all the java servlets using: javac filename.java If you have many compile errors, then you surely have the CLASSPATH wrong. Below is a simple JSP program that you can use to see if you have everything working. Put it in the examples/jsp directory and name it test.jsp.

<%!int count = 0; %> <html> <body> <% count = count + 1; %> This page has been accessed <%= count %> times. </body> </html> Access it a URL like (with the right machine name and port number): http://csci571.usc.edu: 8821/examples/jsp/filename.jsp Each time you hit the refresh button the count should increase. When you want to change a JSP, you have to do some work to get JWS to re-translate the file. JWS creates a directory called 'work' immediately below its home directory. In the work directory is where the servlets are stored (your jsp is parsed and converted automatically to a servlet the first time the jsp is asked for. To get it re-translated, you have to delete the servlet. You just need to know what to delete. The easy way is to cd to the work directory and do a 'rm -rf *', then stop and restart the JWS. That will remove all servlets. It's a bit of overkill, but will certainly work. If you want to be more selective. You may notice that when a jsp is first requested, there is some information displayed in the session window where you originally started the JWS server. You should see something like this: Scratch dir for the JSP engine is: work/%3A43434%2F IMPORTANT: Do not modify the generated servlets The funny looking directory name under work in the first line is the directory that you can delete to have the jsp re-translated so that your jsp file changes will be noticed.