CMPUT 391 Database Management Systems
Web based Applications, Tomcat and Servlets - Lab 3 -
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta The Basic Web Server
Lab 3 CMPUT 391 – Database Management Systems 2 Tomcat and Servlets CGI
‹ CGI – Common Gateway Interface ‹ Processing forms & Generating dynamic content (early solution ) ‹ Spawning an external program, pass the data from the HTML form to the program ‹ Limitation: An expensive process (Spawning an external program)
Lab 3 CMPUT 391 – Database Management Systems 3 Tomcat and Servlets CGI: Illustration
Browser Browser Browser Browser
GET Response Form.cgi
Web Server Web Server Web Server Web Server
Spawn an Read environment external program variables Response
Start form.cgi CGfoI rPmr.ocggria m CGI Program CGI Program CteGrIm Pinroagterasm
time
Lab 3 CMPUT 391 – Database Management Systems 4 Tomcat and Servlets ASP
‹ ASP – Active Server Pages ‹ Microsoft’s answers to CGI programming ‹ ASP page - a Web page with code embedded inside, interpreted by the Web server ‹ Using special HTML tags, VBScript/JavaScript code can be inserted
Lab 3 CMPUT 391 – Database Management Systems 5 Tomcat and Servlets Servlets
‹ Java technology's answer to CGI programming ‹ A Java class handling forms on Java Web servers ‹ Applet -- a little piece of program (client side) ‹ Servlet -- a little piece of program (server side) ‹ A servlet can do everything that a CGI program can ‹ Running inside the JVM along with the Web server itself
Lab 3 CMPUT 391 – Database Management Systems 6 Tomcat and Servlets Servlets: Illustration
Browser Browser Browser Browser
GET Response /Form
Java Web Server Java Web Server Java Web Server Java Web Server
Request Response
Create an Form Instance of Form Form Servlet the servlet if it Servlet Servlet is not loaded Remains loaded
time
Lab 3 CMPUT 391 – Database Management Systems 7 Tomcat and Servlets Servlets Support in Existing Servers
‹ Apache Web Server & some other Java-enabled Web servers ‹ Servlet engine Usually a separate process, not within the same process at the Web server e.g. Tomcat
Lab 3 CMPUT 391 – Database Management Systems 8 Tomcat and Servlets Typical Servlet Engine Implementation
Servlet Engine Web Server
Servlet 1 HTTP Custom TCP/IP traffic Protocol Browser API dispatcher Servlet 2
Servlet N
‹ Tomcat A Servlet Engine for Apache Web Server
Lab 3 CMPUT 391 – Database Management Systems 9 Tomcat and Servlets JSP
‹ JSP – Java Server Pages - Java Version of ASP - A Web page with Java code embedded inside it and running on the Web server ‹ Java’s answer to both CGI and ASP ‹ Compiled into servlets ‹ JSP & servlets can easily interact
Lab 3 CMPUT 391 – Database Management Systems 10 Tomcat and Servlets Tomcat
‹ Servlet &JSP engine for Apache Web Server ‹ An open-source package part of the Apache Software Foundation’s Jakarta project ‹ The Tomcat Web site: – http://jakarta.apache.org/tomcat/index.html
Lab 3 CMPUT 391 – Database Management Systems 11 Tomcat and Servlets Installing Tomcat
‹ Setting the CLASSPATH: the same classpath settings as your JVM ‹ Change the CLASSPATH environment variable from your login shell – Follow the instructions in: http://ugweb.cs.ualberta.ca/~c391/tutorial/softwInstall.html ‹ Test your installation
Lab 3 CMPUT 391 – Database Management Systems 12 Tomcat and Servlets Installation Tips
‹ Use “echo $SHELL” to double check your shell ‹ When editing catalina/conf/server.xml,
Lab 3 CMPUT 391 – Database Management Systems 13 Tomcat and Servlets URL Mapping
‹ Unlike ASP, JSP, etc., servlets have no extension: