Java Server Programming Jeff Schmitt Towson University October 15, 1998.
-
Upload
louisa-rosemary-clarke -
Category
Documents
-
view
219 -
download
1
Transcript of Java Server Programming Jeff Schmitt Towson University October 15, 1998.
Java Server Programming
Jeff SchmittTowson University
October 15, 1998
Java Server Programming
Presentation Topics• Three Tier Information Architecture• CGI and CGI-Wrap• Java Server and servletrunner• JDBC and Oracle• Future developments
Three Tier Architecture
1 Lightweight ClientWeb browser as universal clientJava Applets?
2 Business LogicWeb server--executing programs
3 Database ServerOracle -- accessed by JDBC
HTML Forms
• <FORM ACTION=“http://triton.towson.edu/~schmitt/cgi-bin/program
METHOD=“GET” (or put)• <INPUT NAME="VAR" SIZE="15">• <INPUT TYPE="SUBMIT" NAME="REQUEST"
VALUE="Submit">
Common Gateway Interface
• A standard for interfacing external applications• executable programs placed in special directory
defined on the server• programs run under www (the webserver) userid• read standard input and print standard output• server passes information via Environment variables
REMOTE_HOST QUERY_STRING CONTENT_TYPE
Problems with CGI
• Security concerns• Loading/initializing program and JVM for each
access• Problems sharing/access to files• Control of concurrency
CGI-WRAP
• Nathan Neulinger <[email protected]> • CANS official policy--triton, saber• Access control (allow, deny)• CGI program runs as the user
http://triton.towson.edu/~schmitt/cgi-wrap/program• See: CGIwrap User Instructions
CGI Processing- 3 Steps
1 Read the CGI Parameters Get Method: Query String transmits the data with the URL
stringhttp://www.towson.edu/cgi-bin/stockmarket?stock=IBM&action=buy
Post Method: data is transmitted separately,does not appear in the URL string
2 Process the information3 Transmit the results
Content-type: text/html (then a blank line)<HTML> etc. output
Java Class: CGIParameters
• Needed to access CGI • Adapted from John Carnahan's MOD_JAVA• Parses query string, POST data values, HTTP cookie• Builds a hashtable structure for efficient access• Hides the details of a urlencoded data
Running Java programs as CGI
• Shell script 'javarun' is used• CLASSPATH is established• Shell exits and java starts• Server information passed to Java• Class name taken from cgiwrap • See: javarun source
Learning Server Programming
• Start with basics• Build skills by copying and modifying examples• Guestbook series of projects• Guestbooks 1 and 2 save data in textfile• Guestbook 4 sends notification by email• Guestbook 3 uses JDBC
• Guestbook6 same as Guestbook3 but uses servlet technology
Java Server or Apache plus JRun
• 100% Java code from Sun Microsystems• Same features as regular web server plus servlets• JSP scripting embedded into HTML web pages• JSDK 2.0 will be part of future JDK 1.2 now in beta• Configuration file servlet.properties
– server creates new servlets by chaining one or more servlets
– server can pass additional parameters to servlets
• See: Java Web Server at Sun; JRun at Live Software
Servlet Advantages
• Initialization method when servlet is loaded by server• Servlet stays running• Concurrency control and communication between
threads• Presentation Templates• Page Compilation (JSP)• Powerful, standard JSDK class library from Sun• Server and Servlets are centrally administered
Servlet Session Tracking
• Session tracking is a mechanism for building a sophisticated, stateful model on top of the web's stateless protocol.
• With session tracking, session state is maintained by the server. – creates new sessions– invalidates old sessions, – maintains policies of session persistence.
Java Servlet Development Kit - JSDK
• CLASSPATH jsdk.jar defines classesjavax.servlet and javax.servlet.http
• servletrunner: sun.servlet.http.HttpServer - Can serve only servlets- Lightweight and efficient• See: JSDK API Documentation on triton
CGI script: servletrun
• CANS server policy• Each student chooses a specific port (10000 - 65534)• CGI program similar to javarun• Starts server if necessary • Redirects request to servlet• Works with method of Get (not Post)• See: servletrun source
CGI script: servletstop
• Stops server• Next access to servlet by servletrun will restart
server and new classes will be used• See: servletstop source
Servlet Examples
• HelloServlet• SnoopServlet• SessionServlet• Dukes Bookstore• See: Java Servlet Webpage
JDBC - Java Database Connectivity
• Choices of JDBC driver JDBC Thin or JDBC OCI • Oracle's JDBC Thin driver uses Java sockets to
connect directly to Oracle. Runs as 100% Java, platform independent
• The JDBC OCI drivers call native code libraries directly from JavaProviding a high degree of compatibility with a specific Version of Oracle.
Steps in using JDBC
1 Load the DriverClass.forName ("oracle.jdbc.driver.OracleDriver");
2 Connect to the DB ServerConnection conn = DriverManager.getConnection ("jdbc:oracle:thin:@triton.towson.edu:1521:cosc", account, password);
3 Make and execute an SQL statementrset = stmt.executeQuery ("select * from guestbook6");
Steps in using JDBC (Continued)
4 Process the ResultSetwhile (rset.next ()) { out.println("<TR>")<TD>"+rset.getString (1));}
• See: JDBC Instructions and Oracle JDBC Driver
Future: JSQL
• JSQL is an integration of SQL statements in Java programs.
• It is more concise than JDBC, and more amenable to static analysis and type checking.
• The Oracle database server will store a user’s JSQL program and execute it in the server.
• See: Oracle 8 and Java -- Technical Whitepaper
Future: Oracle8i
• Integrated Sun Java Web server (servlets, JSP)• Oracle’s own Java virtual machine VM• Internet File System -- Windows desktops can attach
directly to database• WebDB -- server-based web development
environment• See: Oracle8i at Oracle
Future: Page Compilation
• Java Server Pages .jsp• Server creates servlets dynamically• Scripting tags embedded in an HTML page
See: catalog.jsp source code
For More Information
See my web pages:• CGIWrap Setup Instructions• Database Page• JDBC Page• Server/Servlet Page• COSC 671 Assigned Projects and Readings