/usr/local/jdk1.2/
and that the compiler executable is in
/usr/local/jdk1.2/bin/
and that the library is in
/usr/local/jdk1.2/lib/
setenv PATH $PATH:/usr/local/jdk1.2/bin
setenv CLASSPATH /usr/local/jdk1.2/lib:.
(Don't forget the colon and the dot at the end).
% javac
% java
If not, don't go any further but fix the path problems now.
public class HelloWorld {
public static void main (String[] argv)
{
System.out.println ("Hello World!");
}
}
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
}
public void doPost (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
}
}
If it compiles, fine, you've got access to the servlet class library.
If not, you need to copy over JSDK.
% cp ~simha/java/ecom/JSDK2.0.tar ~/java/.
% cd ~/java
% tar -xvf JSDK2.0.tar
This will create a directory called JSDK2.0 with the servlet kit.
Note: we'll copy over other things into the java directory from
time to time.
setenv CLASSPATH /usr/local/jdk1.2/lib:$HOME/java/JSDK2.0/lib/jsdk.jar:.
Notice how a jar file requires naming the file. Also, don't
forget the current directory (the ".") at the end.
Either source your .cshrc or logout/in again.
% cp ~simha/java/ecom/jigsaw.tar.gz ~/java/.
% cd ~/java
% gunzip jigsaw.tar.gz
% tar -xvf jigsaw.tar
This will create a directory called Jigsaw.
% ls ~/java/Jigsaw/Jigsaw/classes/jigsaw.zip
setenv CLASSPATH /usr/local/jdk1.2/lib:$HOME/java/JSDK2.0/lib/jsdk.jar:$HOME/java/Jigsaw/Jigsaw/classes/jigsaw.zip:.
% cd ~/java/Jigsaw/Jigsaw
% java Install
This completes the installation, but not the configuration.
% cd ~/java/Jigsaw/Jigsaw/config/
and edit the files admin-server.props and http-server.props.
Now Jigsaw is ready to be fired up.
org.w3c.jigsaw.propfile=/home/joe/java/Jigsaw/Jigsaw/config/admin-server.props
org.w3c.jigsaw.config=/home/joe/java/Jigsaw/Jigsaw/configadm
org.w3c.jigsaw.root=/home/joe/java/Jigsaw/Jigsaw
org.w3c.jigsaw.port=8501
org.w3c.jigsaw.trashdir=/home/joe/java/Jigsaw/Jigsaw/trash
org.w3c.jigsaw.propfile=/home/joe/java/Jigsaw/Jigsaw/config/http-server.props
org.w3c.jigsaw.config=/home/joe/java/Jigsaw/Jigsaw/config
org.w3c.jigsaw.root=/home/joe/java/Jigsaw/Jigsaw
org.w3c.jigsaw.servlet.servlet-log-file=/home/joe/java/Jigsaw/Jigsaw/logs/servlets
org.w3c.jigsaw.space=/home/joe/htdocs
org.w3c.jigsaw.port=8502
% netscape&
% java org.w3c.jigsaw.Main -root /home/joe/java/Jigsaw/Jigsaw
This should run the webserver, which will listen at port 8502 (or
whatever you had used as a port number above).
http://localhost:8502
http://128.14.9.82:8502
as long as you append the port number.
% java org.w3c.jigsaw.Main -root /home/joe/java/Jigsaw/Jigsaw
everytime you want to run the webserver, create a shortcut (alias)
in your .cshrc file:
alias jigsaw "java org.w3c.jigsaw.Main -root /home/joe/java/Jigsaw/Jigsaw"
This way, you can simply type:
% jigsaw
to run it.
% java org.w3c.jigadm.Main -root /home/joe/java/Jigsaw/Jigsaw http://felix:8501
(Note: use your assigned admin port number of course).
alias jigadmin "java org.w3c.jigadm.Main -root /home/joe/java/Jigsaw/Jigsaw http://felix:8501"
Let's assume you want to set up a servlets in the following two ways:
% cd ~/htdocs
% mkdir servlets
Jigsaw is designed to look for servlets from a /servlets directory
off of the document root.
"org.w3c.resources.DirectoryResource".
Doing this will put this string into the textfield right above
the choice-list and will foldup the choice-list.
Then, click on the "Add Resource" button almost at the
bottom of the half-screen. Now you are done with "Resources".
"org.w3c.jigsaw.servlet.ServletDirectoryFrame"
which will get entered in the textfield and cause the
choice-list to foldup. Then click on the "Add Frame" button
below the choice-list.
NOTE: you can place additional servlets in this directory and
they will automatically load when invoked. Thus, the admin
stuff is done only for new directories.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class HelloWorld extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// Set the content type of the response.
resp.setContentType ("text/html");
// Create a PrintWriter to write the response.
java.io.PrintWriter out = new PrintWriter (resp.getOutputStream());
// The first part of the response.
out.println ("");
out.println ("
% javac HelloWorld.java
% cp HelloWorld.class ~/htdocs/servlets/.
http://localhost:8502/servlets/HelloWorld
and save it in the /htdocs directory.
mSQL is a commercial Unix-dbase package created by Hughes, Australia.
It's free (including source) for all-but commercial use;
there are license agreements (reasonably priced) for commercial
use, i.e., including it in a product.
mSQL supports a subset of SQL, comes with a tiny admin tool,
an SQL interpreter, a script language, and a web-like scripting
language for server-side includes in webpages. They claim
strong performance with small data sets and reasonable performance
with large data sets.
mSQL and mSQL documentation can be found at:
http://www.hughes.com.au
You can copy mSQL from my directory. The manual will be placed on
the course website.
% cp ~simha/java/ecom/msql-2.0.9.tar.gz ~/java/.
% gunzip msql-2.0.9.tar.gz
% tar -xvf msql-2.0.9.tar
% cd ~simha/java/ecom/msql-2.0.9/
% make target
This script discovers your machine and environment and creates
a configuration for compilation. The output to the screen
is something like:
Making target directory for Solaris-2.6-Sparc
Building directory tree.
Adding common
Adding conf
Adding lang-common
Adding lite
Adding makedepend
Adding makegen
Adding msql
Adding regexp
Adding tests
Adding tests/rtest.src
Adding w3-msql
Adding w3-msql/tests
Adding sym-links
............................................................
............................................................
Build of target directory for Solaris-2.6-Sparc complete
% cd targets/Solaris-2.6-Sparc/
% setup
The output is something like:
Starting configuration of mSQL 2.
creating cache ./config.cache
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
... [stuff left out]
Ready to build mSQL.
You may wish to check "site.mm" although the defaults should be
fine. When you're ready, type "make all" to build the software
n
msql-2.0.9/bin
% cd ~/java/msql-2.0.9/
% mkdir bin
INST_DIR= /home/joe/java/msql-2.0.9/bin
% make all
This will take time and produce a lot of output, something like:
Regenerating Makefile.
......................................................
Done.
Starting make for mSQL-2
--> [common] directory
Regenerating Makefile.
.....................................
...[stuff left out]
Make of mSQL-2 complete.
You should now install mSQL-2 using make install
% make install
This should produce output like:
Starting install for mSQL-2
...[stuff left out]
Installation of mSQL-2 complete.
% msql2d &
% msql testdb
msql> create table testtable (age integer) \g
This will create a table that you can work with, e.g.,
msql> select * from testtable \g
To shutdown the server, type:
% msqladmin shutdown
- Simply typing msqladmin will list commands.
% cp ~simha/java/ecom/bank_schema.sql
% msqladmin create bank
% msql bank < bank_schema.sql
% cp ~simha/java/ecom/mSQL-JDBC-1.tar.gz ~/java/.
% gunzip mSQL-JDBC-1.tar.gz
% tar -xvf mSQL-JDBC-1.tar
setenv CLASSPATH /usr/local/jdk1.2/lib:$HOME/java/JSDK2.0/lib/jsdk.jar:$HOME/java/Jigsaw/Jigsaw/classes/jigsaw.zip:$HOME/java/mSQL-JDBC-1.0/msql-jdbc-1-0.jar:.
import java.sql.*;
import java.net.*;
import java.io.*;
public class TestJDBC {
public static void main(String args[]) {
// The SQL query.
String sql = "select * from emp";
System.out.println("Executing: " + sql);
// Create a driver instance.
try {
Class.forName("com.imaginary.sql.msql.MsqlDriver").newInstance();
// Make a connection.
String url = "jdbc:msql://localhost:8114/test";
Connection con = DriverManager.getConnection(url, "simha", "");
if (con == null) {
System.out.println ("Connection unsuccessful");
System.exit(0);
}
else {
System.out.println ("Connection successful. Continuing ...");
}
// Make a statement.
Statement s = con.createStatement();
if (s == null) {
System.out.println ("Statement creation unsuccessful");
System.exit(0);
}
else {
System.out.println ("Statement creation successful ... continuing");
}
// Execute the SQL statement.
if ( s.execute (sql) ) {
ResultSet r = s.getResultSet();
ResultSetMetaData meta = r.getMetaData();
int cols = meta.getColumnCount();
int rownum = 0;
// Iterate over the rows - get one row at a time.
while( r.next() ) {
rownum++;
System.out.println("Row: " + rownum);
for(int i=0; i
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.net.*;
import java.io.*;
public class TestJDBCServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// Set the content type of the response.
resp.setContentType ("text/html");
// Create a PrintWriter to write the response.
java.io.PrintWriter out = new PrintWriter (resp.getOutputStream());
// The first part of the response.
out.println ("");
out.println ("
http://localhost:8502/servlets/TestJDBCServlet
http://www.yahoo.com/search?music
Here, the text field contains the string "music".
NOTE: we will not cover html forms here. For details, see my
tutorial on HTML.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class TestForm extends HttpServlet {
public void doPost (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
// Set the content type of the response.
resp.setContentType ("text/html");
// Create a PrintWriter to write the response.
java.io.PrintWriter out = new PrintWriter (resp.getOutputStream());
// The first part of the response.
out.println ("");
out.println ("