Deploying Web Applications to Tomcat Server Chun Guo
Deployment vs. Development Development Create the web application Deployment Make the web application available to use (publically accessible through URL). Publish your application on the server!
IP address, URL and DNS IP address – An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. – IP addresses are represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots – e.g. IP address for ILS website is
IP address, URL and DNS URL and DNS – The Domain Name System (DNS) is a hierarchical distributed naming system that translates easily remembered domain names (URL) to the numerical IP addresses. – It serves as the phone book for the Internet by translating human-friendly computer hostnames into IP addresses.
Look up IP address Check the IP address for a given domain – ping “domain name”
Check your own IP Address Windows – ipconfig Mac – ifconfig
The Large Picture
Outline Tomcat Basics Tomcat Administration Deploy web applications to Tomcat server – WAR file – Deployment folder
Outline Tomcat Basics Tomcat Administration Deploy web applications to Tomcat server – WAR file – Deployment folder
Server Hardware Software Database Server Web Server
Tomcat Basics What is Tomcat? Web container – Manage Java Servlets HTTP Web server – Deliver web pages on the request to clients. – Receive content from clients. – Create HTML documents dynamically ("on-the- fly")
Install Tomcat Windows – Installer (apache-tomcat exe) Mac – Unzip
Outline Tomcat Basics Tomcat Administration Deploy web applications to Tomcat server – WAR file – Deployment folder
Look inside the Tomcat directory /tomcat /bin startup.sh shutdown.sh /conf server.xml /lib/logs/webapps /ROOT/deployedApp1 /WEB-INF web.xml /lib /classes /META-INF /deployedApp2 /work
Start Tomcat Server Windows > startup.bat Mac $ cd “TOMCAT_HOME”/bin $./startup.sh Test –
Shut Down Tomcat Server Windows > shutdown.bat Mac $ cd “TOMCAT_HOME”/bin $./shutdown.sh Test –
Look inside the Tomcat directory /tomcat /bin startup.sh shutdown.sh /conf server.xml /lib/logs/webapps /ROOT/deployedApp1 /WEB-INF web.xml /lib /classes /META-INF /deployedApp2 /work
Tomcat Architecture Connector HTTP 1.1 Connector HTTP 1.1 Web application A Connector AJP 1.3 Connector AJP 1.3 Web application B Web application C Web application D HTTP Request HTTP Response AJP Response AJP Request TOMCAT Engine Host Context More about server.xml:
Host, Context Host Context
Tomcat configuration file (server.xml) <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <Host name="localhost" appBase="webapps” unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
Change Default Port In “server.xml” … <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> … <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> …
Change Default Port In “server.xml” … <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> … <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> …
Outline Tomcat Basics Tomcat Administration Deploy web applications to Tomcat server – WAR file – Deployment folder
Package your web application Export your project to as a WAR file. – A WAR file (or Web application ARchive) is a JAR file used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages (HTML and related files) and other resources that together constitute a web application.
Package your web application In Eclipse, right click on your project name; go to “Export”, and click “WAR file ”.
Package your web application Click “Browse” to select a location to store your WAR file, and click “Finish”.
Deploy your web application Copy your WAR file to the TOMCAT_HOME/webapps directory. Restart Tomcat. –./shutdown.sh –./startup.sh Test Check the TOMCAT_HOME/webapps directory. A new directory named “myApp” is created.
Look inside your application directory /myApp /WEB-INF /classes /lib web.xml Index.html/img
Look inside your application directory /myApp /WEB-INF /classes /lib web.xml Index.html/img This is the root directory of the web application. All static content (e.g. HTML files, images) are stored here.
Look inside your application directory /myApp /WEB-INF /classes /lib web.xml Index.html/img WEB-INF directory is not part of the public document.
Look inside your application directory /myApp /WEB-INF /classes /lib web.xml Index.html/img This directory is where servlet and utility classes are located.
Look inside your application directory /myApp /WEB-INF /classes /lib web.xml Index.html/img This directory contains Java Archive files that the web application depends upon. For example, this is where you would place a JAR file that contained a JDBC driver.
Look inside your application directory /myApp /WEB-INF /classes /lib web.xml Index.html/img web application deployment descriptor
Web Application Deployment Descriptor: web.xml myApp index.html index.htm index.jsp default.html default.htm default.jsp Web_compute Web_compute /Web_compute
Welcome page The welcome-file-list element contains a list of file names When the URL request is a directory name, Tomcat automatically brings the first file on the list If that file is not found, the server then tries the next file in the list, and so on This file can be of any type, e.g., HTML, JSP, image, etc. index.html index.htm index.jsp default.html default.htm default.jsp index.html index.htm index.jsp default.html default.htm default.jsp
Welcome page The welcome-file-list element contains a list of file names When the URL request is a directory name, Tomcat automatically brings the first file on the list If that file is not found, the server then tries the next file in the list, and so on This file can be of any type, e.g., HTML, JSP, image, etc. Web_compute index.htm index.jsp default.html default.htm default.jsp Web_compute index.htm index.jsp default.html default.htm default.jsp
Servlet Declaration and Mapping The element declares a Servlet The element maps a URL to a specific Servlet – The URL is relative to the application’s base URL ( ) Web_compute Web_compute /Web_compute Web_compute Web_compute /Web_compute
Servlet Declaration and Mapping The element declares a Servlet The element maps a URL to a specific Servlet – The URL is relative to the application’s base URL ( ) Web_compute Web_compute /Web_compute Web_compute Web_compute /Web_compute
Work Flow The user submits an HTTP request Tomcat finds the servlet based on the URL and the deployment descriptor ( web.xml ) and passes the request to the servlet The servlet writes an HTML page containing the response Tomcat returns the HTML page to the user
References step-step-guide#.URM9VlqWkSg /Lectures/26-tomcat.ppt /Lectures/26-tomcat.ppt step-step-guide#.URM9VlqWkSg step-step-guide#.URM9VlqWkSg ing/howto/Tomcat_HowTo.html
Questions?