Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Server Programming Jeff Schmitt Towson University October 15, 1998.

Similar presentations


Presentation on theme: "Java Server Programming Jeff Schmitt Towson University October 15, 1998."— Presentation transcript:

1 Java Server Programming Jeff Schmitt Towson University October 15, 1998

2 Java Server Programming Presentation Topics Three Tier Information Architecture CGI and CGI-Wrap Java Server and servletrunner JDBC and Oracle Future developments

3 Three Tier Architecture 1Lightweight Client Web browser as universal client Java Applets? 2Business Logic Web server--executing programs 3Database Server Oracle -- accessed by JDBC

4 HTML Forms <FORM ACTION= “http://triton.towson.edu/~schmitt/cgi-bin/program METHOD=“GET” (or put)

5 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

6 Problems with CGI Security concerns Loading/initializing program and JVM for each access Problems sharing/access to files Control of concurrency

7 CGI-WRAP Nathan Neulinger CANS official policy--triton, saberCANS official policy Access control (allow, deny) CGI program runs as the user http://triton.towson.edu/~schmitt/cgi-wrap/program See: CGIwrap User InstructionsCGIwrap User Instructions

8 CGI Processing- 3 Steps 1Read the CGI Parameters Get Method: Query String transmits the data with the URL string http://www.towson.edu/cgi- bin/stockmarket?stock=IBM&action=buy Post Method: data is transmitted separately, does not appear in the URL string 2Process the information 3Transmit the results Content-type: text/html (then a blank line) etc. output

9 Java Class: CGIParameters Needed to access CGI Adapted from John Carnahan's MOD_JAVAMOD_JAVA Parses query string, POST data values, HTTP cookie Builds a hashtable structure for efficient access Hides the details of a urlencoded data

10 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 sourcejavarun source

11 Learning Server Programming Start with basics Build skills by copying and modifying examples Guestbook series of projects Guestbooks 1 and 2 save data in textfileGuestbooks 1 and 2 Guestbook 4 sends notification by email Guestbook 3 uses JDBCGuestbook 3 Guestbook6 same as Guestbook3 but uses servlet technologyGuestbook6

12 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 SoftwareJava Web Server JRun

13 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

14 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.

15 Java Servlet Development Kit - JSDK CLASSPATH jsdk.jar defines classes javax.servlet and javax.servlet.http servletrunner: sun.servlet.http.HttpServer -Can serve only servlets -Lightweight and efficient See: JSDK API Documentation on tritonJSDK API Documentation

16 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 sourceservletrun source

17 CGI script: servletstop Stops server Next access to servlet by servletrun will restart server and new classes will be used See: servletstop sourceservletstop source

18 Servlet Examples HelloServlet SnoopServlet SessionServlet Dukes Bookstore See: Java Servlet WebpageJava Servlet Webpage

19 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 Java Providing a high degree of compatibility with a specific Version of Oracle.

20 Steps in using JDBC 1Load the Driver Class.forName ("oracle.jdbc.driver.OracleDriver"); 2Connect to the DB Server Connection conn = DriverManager.getConnection ( "jdbc:oracle:thin:@triton.towson.edu:1521:cosc", account, password); 3Make and execute an SQL statement rset = stmt.executeQuery ("select * from guestbook6");

21 Steps in using JDBC (Continued) 4Process the ResultSet while (rset.next ()) { out.println(" ") "+rset.getString (1)); } See: JDBC Instructions and Oracle JDBC DriverJDBC InstructionsOracle JDBC Driver

22 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

23 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 OracleOracle8i

24 Future: Page Compilation Java Server Pages.jsp Server creates servlets dynamically Scripting tags embedded in an HTML page See: catalog.jsp source codecatalog.jsp source code

25 For More Information See my web pages: CGIWrap Setup Instructions Database Page JDBC Page Server/Servlet Page COSC 671 Assigned Projects and Readings


Download ppt "Java Server Programming Jeff Schmitt Towson University October 15, 1998."

Similar presentations


Ads by Google