Servlet and Tomcat Tutorial
ECT 7130
Download Tomcat
[Link]
[Link]/tomcat/tomcat-5/v5.5.28/bin/[Link]
Put under C:\ and unzip to C:\apachetomcat-5.5.28
Starting and Stopping Tomcat
In command line window, set JAVA_HOME=c:\Program
Files\Java\jdk1.5.0_03 (depends on your jdk directory
name, for example, maybe yours is jdk1.6.x_xx)
C:\apache-tomcat-5.5.28\bin>startup
C:\apache-tomcat-5.5.28\bin>shutdown
Open a browser and type in
[Link]
Web Application Directory Structure
webapps
liangweb
Static files, such as
HTML files and JSP
files in the directory
that is the document
root of your Web
Application
*.html
*.jsp
WEB-INF
[Link]
classes
*.class
Packages (e.g., chapter35)
*.class
lib
*.jar
Compiling Servlets
Set classpath=%classpath%;c:\apache-tomcat5.5.28\common\lib\[Link]
Create directory
c:\apache-tomcat5.5.28\webapps\liangweb\WEB-INF\classes
Copy slide/book/[Link] into
c:\apache-tomcat5.5.28\webapps\liangweb\WEB-INF\classes
Download
[Link]/liang/intro6e/supp
lement/[Link]
to
c:\apache-tomcat5.5.28\webapps\liangweb\WEB-INF
Run by typing
[Link]
For JDBC Programs
Create a directory liangweb/META-INF
Create a file [Link] with the following content
<Context path="/liangweb" docBase="liangweb" debug="5
reloadable="true" crossContext="true">
<Resource name="jdbc/TestDB" auth="Container
type="[Link]
driverClassName="[Link]
url="jdbc:mysql://localhost;DatabaseName=javabook"
username="scott" password="tiger"
maxActive="300" maxIdle="30" maxWait="10000" />
</Context>
Put [Link] under apache-tomcat5.5.28/common/lib/
You have to startup your MySQL database
(or MySQL service) with net start mysql
Run JDBC Servlet Programs
Under slide/book, you can find [Link] and
[Link]. Do the following tasks:
1. Put the html file under apache-tomcat/webapps/liangweb. Put the class file
under apache-tomcat/webapps/liangweb/WEB-INF/classes.
2. Startup tomcat, and type the URL
[Link] in a browser.
3. Test whether you can successfully insert the record you input in the form into
the database.
4. Before you do that, you have to create a table "Address" with the lastname,
firstname,..., zip fields in your MySQL database.
You can also test [Link]/class, [Link]/class and
[Link]/class in a similar way.
Part II: JSP
Startup tomcat
Copy the following jsp files to apachetomecat\webapps\liangweb and run
[Link]
[Link]
[Link]
[Link]
[Link] and [Link]
[Link]
[Link] (modify this file according to Page 31 of
Chapter 40 ppt)
Copy [Link] to liangweb\WEB-INF\classes\chapter35\
Compile it into [Link]
[Link]
Do the same for [Link] + [Link]
Do the same for [Link] + [Link]
Do the same for [Link] + [Link]
Do the same for [Link] + [Link]
The JDBC Example
Copy [Link], [Link],
[Link], [Link] to liangweb
Copy [Link] to liangweb/WEBINF/classes/chapter35 and compile it to
[Link]
Startup MySQL
Run [Link]