SlideShare a Scribd company logo
Tomcat and Servlets 
HaifengLiu
Tutorial Overview 
„Tomcat Overview 
„Setting Up and Running Tomcat on CDF 
„Installing and Running Servletson CDF 
„Setting up SysdeoEclipse Tomcat Launcher plugin 
„FAQ?
Tomcat Overview 
„Tomcatis the servletcontainer 
„History: 
‰ASF: JServ–performance 
‰Sun: ServletEngine --specification 
„Requirements and Quality Goals: 
‰Strict adherence to Sun’s JSP/Servletspecification, Interoperability, Modifiability, Performance, Scalability, High-Availability, Security, … 
---Jakarta Tomcat
Tomcat System
Setting Up Tomcat on CDF 
„Status: Installed with user privileges in 
/u/csc309h/lib/brad/tomcat-5.0.27 
„Step 1 –go to website, read instructions 
http://www.cs.toronto.edu/~delara/courses/csc309/resources/csc309guide.html#WebServer 
„Step 2 –download the tar file tomcat.tar.gz 
„Step 3 –untarit (tar xvztomcat.tar.gz) and copy the files into a working directory which is referedas 
e.g. ~/csc309/ 
„Inside tomcat: 
Bin, conf, logs, webapps, work
Start Tomcat Server 
„Step 1 --cd~/csc309/tomcat/bin 
„Step 2 --Run the script start.sh(may need to chmoda+x*.sh) ./start.sh 
„Step 3 --Enter the port number. Tomcat will use 3 ports, the number entered and the next two (e.g., if you are assigned port 32000, tomcat will use 32000, 32001, 32002). 
„Step 4 –check /bin/ps-ef| grepyour_user_id 
„Step 5 –view http://localhost:your_port_number
Tomcat tutorail
Stop Tomcat Server 
„To stop your server, run bin/stop.sh. 
„Always remember to stop your server before logging off CDF.
Directory Structure 
„Bin –Startup/shutdown scripts and other useful files. 
„Conf –Configuration files, including modules.xml, server.xml, and a number of apps-<name>.xml. 
„Logs –event log file for each day 
„Webapps–web application files 
„Wok --intermediate files (such as compiled JSP files) during its work. If you delete this directory while Tomcat is running you will not be able to execute JSP pages!
Installing and Compiling Servlets 
„Step 1 --Download the sample files, untarit, put into webapps 
„Step 2 --Compile the Java class 
‰Include the following jar file in your CLASSPATH 
/u/csc309h/lib/tomcat-5.0.27/common/lib/servlet-api.jar. 
setenvCLASSPATH ${CLASSPATH}: /u/csc309h/lib/tomcat- 
5.0.27/common/lib/servlet-api.jar 
‰cd~/csc309/tomcat/webapps/csc309/WEB-INF/classes 
‰Compile the servletjavacHelloWorld.java 
„Step 3 --Start Tomcat 
„Step 4 –Start Browser: 
http://127.0.0.1:yourPortNumber/csc309/servlet/HelloWorld
HelloWorldInterface
Adding a Servletto a Web Application 
„Step 1 –Download PrintEnv.javaand copy it to ~/csc309/tomcat/webapps/csc309/WEB-INF/classes 
„Step 2 --Compile PrintEnv.java 
„Step 3 –Add the following entries to the application descriptor located at ~/csc309/tomcat/webapps/csc309/WEB-INF/web.xml. 
<servlet> 
<servlet-name>PrintEnv</servlet-name> 
<servlet-class>PrintEnv</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>PrintEnv</servlet-name> 
<url-pattern>/servlet/PrintEnv</url-pattern> 
</servlet-mapping> 
„Step 4 --Restart Tomcat 
„Step 5 –Open browser to http://127.0.0.1:yourPortNumber/csc309/servlet/PrintEnv
PrintEnvInterface
SysdeoEclipse Tomcat Launcher plugin 
„Starting, stopping and restarting Tomcat 4.x, 5.0.x, 3.3 
„Registering Tomcat process to Eclipse debugger 
„Creating a WAR project (wizard can update server.xmlfile) 
„Adding Java Projects to Tomcat classpath 
„Setting Tomcat JVM parameters, classpathand bootclasspath 
„Exporting a Tomcat project to a WAR File 
„Choosing Tomcat configuration file 
„Capability to use a special Tomcat classloaderto have classes in several java projects loaded at the same classloaderlevel than classes in a Tomcat project, see readmeDevLoader.html(Thanks Martin Kahr)
Software Prerequisite 
„Tomcat Server – ”http://jakarta.apache.org/tomcat/” 
„Eclipse 3.X – “http://www.eclipse.org/downloads/index.php” 
„SysdeoEclipse tomcat Launcher plugin-- 
”http://www.sysdeo.com/eclipse/tomcatPlugin. 
html”
Setup Tomcat in Eclipse 
„Enable tomcat 
‰Go to the menu "Window-> Preferences" 
‰go to "Tomcat" and select your Tomcat version 
‰adjust the field "Tomcat Home" to point to the install directory 
„Add a new user 
‰scroll down the menu point "Tomcat" and click the item "Tomcat Manager App" 
‰add a username and a password 
‰click on "Add user to tomcat-users.xml" 
„Test Start Tomcat Server
HelloWorldExample 
„Open a new project 
‰select "Tomcat Project"..., click Next button 
‰call our new project "Hello World" 
‰adjust URI http://localhost:8080/HelloWorld/hello 
„create a new class named HelloServletin the directory WEB-INF/src 
„create the file web.xmlin the directory WEB- INF (Note: not in WEB-INF/src!!!) 
„Start browser "http://localhost:8080/HelloWorld/hello"
HelloServlet 
importjava.io.*; 
importjavax.servlet.http.*; 
importjavax.servlet.*; 
publicclass HelloServletextends HttpServlet{ 
publicvoid doGet(HttpServletRequestreq, 
HttpServletResponseres) throws ServletException, 
IOException{ 
PrintWriterout = res.getWriter(); 
out.println("Hello, Brave new World!"); 
out.close(); 
} 
}
Web.xml 
<!DOCTYPE web-app PUBLIC 
'-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 
'http://java.sun.com/dtd/web-app_2_3.dtd'> 
<web-app> 
<servlet> 
<servlet-name>hello</servlet-name> 
<servlet-class>HelloServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>hello</servlet-name> 
<url-pattern>/hello</url-pattern> 
</servlet-mapping> 
</web-app>

More Related Content

PPT
Apache TomEE - Tomcat with a kick
PDF
Integrating Tomcat And Apache On Windows
PDF
Tomcat and apache httpd training
PDF
Apache Tomcat + Java EE = Apache TomEE
PPT
Tomcat configuration
PPT
PPTX
Web container and Apache Tomcat
PDF
How to monitor and manage Apache Tomcat
Apache TomEE - Tomcat with a kick
Integrating Tomcat And Apache On Windows
Tomcat and apache httpd training
Apache Tomcat + Java EE = Apache TomEE
Tomcat configuration
Web container and Apache Tomcat
How to monitor and manage Apache Tomcat

What's hot (20)

PPTX
Creating your own AtoM demo data set for re-use with Vagrant
PPT
Auxiliary : Tomcat
DOC
Integration of apache with tomcat
PDF
Tomcat next
DOC
Integrating open am with liferay portal
DOCX
Apache tomcat
PDF
Architecting Large Enterprise Java Projects
PPTX
Information on Tomcat in cPanel & WHM
PPTX
Devopstore
PPTX
Comprehensive Information on Tomcat
PPTX
PDF
Glassfish Web Stack Launch Jyri Virkki V2
PPTX
플랫폼 통합을 위한 Client Module 개발 & 배포
DOC
Installation of Dspace in Windows OS: A Complete Documentation
PDF
JBoss Snowdrop
PPTX
How to install laravel framework in windows
PDF
Accessing Oracle 11 g on Mac OS (10.7.5) using Oracle Virtual Box
PDF
Aeon mike guide transparent ssl filtering (1)
PDF
Aeon mike guide transparent ssl filtering
PPTX
How to install ReactJS software
Creating your own AtoM demo data set for re-use with Vagrant
Auxiliary : Tomcat
Integration of apache with tomcat
Tomcat next
Integrating open am with liferay portal
Apache tomcat
Architecting Large Enterprise Java Projects
Information on Tomcat in cPanel & WHM
Devopstore
Comprehensive Information on Tomcat
Glassfish Web Stack Launch Jyri Virkki V2
플랫폼 통합을 위한 Client Module 개발 & 배포
Installation of Dspace in Windows OS: A Complete Documentation
JBoss Snowdrop
How to install laravel framework in windows
Accessing Oracle 11 g on Mac OS (10.7.5) using Oracle Virtual Box
Aeon mike guide transparent ssl filtering (1)
Aeon mike guide transparent ssl filtering
How to install ReactJS software
Ad

Viewers also liked (18)

PPT
Java build tool_comparison
PDF
Releasing Projects Using Maven
PPTX
Building java projects with maven
PDF
Java Build Tool course in 2011
PDF
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
PDF
PDF
Java Builds with Maven and Ant
PPTX
Jboss Tutorial Basics
PDF
JEE Programming - 07 EJB Programming
PDF
JBoss Application Server 7
PPT
WebLogic Deployment Plan Example
PPT
Weblogic configuration & administration
PDF
Oracle Web Logic server
PPTX
Where and when to use the Oracle Service Bus (OSB)
PPT
Oracle SOA Suite 11g Mediator vs. Oracle Service Bus (OSB)
PPTX
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
PDF
Oracle OSB Tutorial 1
PPT
Oracle WebLogic Server Basic Concepts
Java build tool_comparison
Releasing Projects Using Maven
Building java projects with maven
Java Build Tool course in 2011
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
Java Builds with Maven and Ant
Jboss Tutorial Basics
JEE Programming - 07 EJB Programming
JBoss Application Server 7
WebLogic Deployment Plan Example
Weblogic configuration & administration
Oracle Web Logic server
Where and when to use the Oracle Service Bus (OSB)
Oracle SOA Suite 11g Mediator vs. Oracle Service Bus (OSB)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
Oracle OSB Tutorial 1
Oracle WebLogic Server Basic Concepts
Ad

Similar to Tomcat tutorail (20)

PDF
Apache Tomcat 8 Application Server
PDF
Spring Live Sample Chapter
PDF
Mc sl54 051_ (1)
PPT
Web Applications and Deployment
PPT
Introduction to Java Servlets and JSP (1).ppt
PPT
Tomcat Configuration (1)
DOCX
Integrating tomcat with apache
PPT
Lect06 tomcat1
PPT
Tomcat server
PPT
Tomcat Server
PDF
Tomcat + other things
PPTX
PPT
Tumbleweed intro
PPT
Ta Javaserverside Eran Toch
PPT
Java Servlets
PDF
Struts2 tutorial
PDF
Struts2 tutorial
PDF
Struts2 tutorial
DOC
Java Servlets & JSP
Apache Tomcat 8 Application Server
Spring Live Sample Chapter
Mc sl54 051_ (1)
Web Applications and Deployment
Introduction to Java Servlets and JSP (1).ppt
Tomcat Configuration (1)
Integrating tomcat with apache
Lect06 tomcat1
Tomcat server
Tomcat Server
Tomcat + other things
Tumbleweed intro
Ta Javaserverside Eran Toch
Java Servlets
Struts2 tutorial
Struts2 tutorial
Struts2 tutorial
Java Servlets & JSP

Recently uploaded (20)

PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Funds Management Learning Material for Beg
PDF
Introduction to the IoT system, how the IoT system works
PPTX
newyork.pptxirantrafgshenepalchinachinane
PPTX
E -tech empowerment technologies PowerPoint
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPT
Ethics in Information System - Management Information System
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
artificialintelligenceai1-copy-210604123353.pptx
PPTX
t_and_OpenAI_Combined_two_pressentations
DOC
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
The Ikigai Template _ Recalibrate How You Spend Your Time.pdf
PPTX
Digital Literacy And Online Safety on internet
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
SAP Ariba Sourcing PPT for learning material
Power Point - Lesson 3_2.pptx grad school presentation
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Funds Management Learning Material for Beg
Introduction to the IoT system, how the IoT system works
newyork.pptxirantrafgshenepalchinachinane
E -tech empowerment technologies PowerPoint
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Ethics in Information System - Management Information System
presentation_pfe-universite-molay-seltan.pptx
artificialintelligenceai1-copy-210604123353.pptx
t_and_OpenAI_Combined_two_pressentations
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
The New Creative Director: How AI Tools for Social Media Content Creation Are...
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
The Ikigai Template _ Recalibrate How You Spend Your Time.pdf
Digital Literacy And Online Safety on internet
SASE Traffic Flow - ZTNA Connector-1.pdf
SAP Ariba Sourcing PPT for learning material

Tomcat tutorail

  • 1. Tomcat and Servlets HaifengLiu
  • 2. Tutorial Overview „Tomcat Overview „Setting Up and Running Tomcat on CDF „Installing and Running Servletson CDF „Setting up SysdeoEclipse Tomcat Launcher plugin „FAQ?
  • 3. Tomcat Overview „Tomcatis the servletcontainer „History: ‰ASF: JServ–performance ‰Sun: ServletEngine --specification „Requirements and Quality Goals: ‰Strict adherence to Sun’s JSP/Servletspecification, Interoperability, Modifiability, Performance, Scalability, High-Availability, Security, … ---Jakarta Tomcat
  • 5. Setting Up Tomcat on CDF „Status: Installed with user privileges in /u/csc309h/lib/brad/tomcat-5.0.27 „Step 1 –go to website, read instructions http://www.cs.toronto.edu/~delara/courses/csc309/resources/csc309guide.html#WebServer „Step 2 –download the tar file tomcat.tar.gz „Step 3 –untarit (tar xvztomcat.tar.gz) and copy the files into a working directory which is referedas e.g. ~/csc309/ „Inside tomcat: Bin, conf, logs, webapps, work
  • 6. Start Tomcat Server „Step 1 --cd~/csc309/tomcat/bin „Step 2 --Run the script start.sh(may need to chmoda+x*.sh) ./start.sh „Step 3 --Enter the port number. Tomcat will use 3 ports, the number entered and the next two (e.g., if you are assigned port 32000, tomcat will use 32000, 32001, 32002). „Step 4 –check /bin/ps-ef| grepyour_user_id „Step 5 –view http://localhost:your_port_number
  • 8. Stop Tomcat Server „To stop your server, run bin/stop.sh. „Always remember to stop your server before logging off CDF.
  • 9. Directory Structure „Bin –Startup/shutdown scripts and other useful files. „Conf –Configuration files, including modules.xml, server.xml, and a number of apps-<name>.xml. „Logs –event log file for each day „Webapps–web application files „Wok --intermediate files (such as compiled JSP files) during its work. If you delete this directory while Tomcat is running you will not be able to execute JSP pages!
  • 10. Installing and Compiling Servlets „Step 1 --Download the sample files, untarit, put into webapps „Step 2 --Compile the Java class ‰Include the following jar file in your CLASSPATH /u/csc309h/lib/tomcat-5.0.27/common/lib/servlet-api.jar. setenvCLASSPATH ${CLASSPATH}: /u/csc309h/lib/tomcat- 5.0.27/common/lib/servlet-api.jar ‰cd~/csc309/tomcat/webapps/csc309/WEB-INF/classes ‰Compile the servletjavacHelloWorld.java „Step 3 --Start Tomcat „Step 4 –Start Browser: http://127.0.0.1:yourPortNumber/csc309/servlet/HelloWorld
  • 12. Adding a Servletto a Web Application „Step 1 –Download PrintEnv.javaand copy it to ~/csc309/tomcat/webapps/csc309/WEB-INF/classes „Step 2 --Compile PrintEnv.java „Step 3 –Add the following entries to the application descriptor located at ~/csc309/tomcat/webapps/csc309/WEB-INF/web.xml. <servlet> <servlet-name>PrintEnv</servlet-name> <servlet-class>PrintEnv</servlet-class> </servlet> <servlet-mapping> <servlet-name>PrintEnv</servlet-name> <url-pattern>/servlet/PrintEnv</url-pattern> </servlet-mapping> „Step 4 --Restart Tomcat „Step 5 –Open browser to http://127.0.0.1:yourPortNumber/csc309/servlet/PrintEnv
  • 14. SysdeoEclipse Tomcat Launcher plugin „Starting, stopping and restarting Tomcat 4.x, 5.0.x, 3.3 „Registering Tomcat process to Eclipse debugger „Creating a WAR project (wizard can update server.xmlfile) „Adding Java Projects to Tomcat classpath „Setting Tomcat JVM parameters, classpathand bootclasspath „Exporting a Tomcat project to a WAR File „Choosing Tomcat configuration file „Capability to use a special Tomcat classloaderto have classes in several java projects loaded at the same classloaderlevel than classes in a Tomcat project, see readmeDevLoader.html(Thanks Martin Kahr)
  • 15. Software Prerequisite „Tomcat Server – ”http://jakarta.apache.org/tomcat/” „Eclipse 3.X – “http://www.eclipse.org/downloads/index.php” „SysdeoEclipse tomcat Launcher plugin-- ”http://www.sysdeo.com/eclipse/tomcatPlugin. html”
  • 16. Setup Tomcat in Eclipse „Enable tomcat ‰Go to the menu "Window-> Preferences" ‰go to "Tomcat" and select your Tomcat version ‰adjust the field "Tomcat Home" to point to the install directory „Add a new user ‰scroll down the menu point "Tomcat" and click the item "Tomcat Manager App" ‰add a username and a password ‰click on "Add user to tomcat-users.xml" „Test Start Tomcat Server
  • 17. HelloWorldExample „Open a new project ‰select "Tomcat Project"..., click Next button ‰call our new project "Hello World" ‰adjust URI http://localhost:8080/HelloWorld/hello „create a new class named HelloServletin the directory WEB-INF/src „create the file web.xmlin the directory WEB- INF (Note: not in WEB-INF/src!!!) „Start browser "http://localhost:8080/HelloWorld/hello"
  • 18. HelloServlet importjava.io.*; importjavax.servlet.http.*; importjavax.servlet.*; publicclass HelloServletextends HttpServlet{ publicvoid doGet(HttpServletRequestreq, HttpServletResponseres) throws ServletException, IOException{ PrintWriterout = res.getWriter(); out.println("Hello, Brave new World!"); out.close(); } }
  • 19. Web.xml <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'> <web-app> <servlet> <servlet-name>hello</servlet-name> <servlet-class>HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> </web-app>