Professional Documents
Culture Documents
Haifeng Liu
Tutorial Overview
Tomcat Overview
Setting Up Tomcat
Running Tomcat
Installing and Running Servlets
FAQ?
Tomcat Overview
/u/csc309h/lib/NetBeans3.6/bin/runide.sh &
Debugging Servlet – Cont’d
Under the Debug menu, click on "Start Session" and then on "Attac
h...“, set Host and Port number. If everything went well you should s
ee the following messages on the "Debugger Console" tab in the lo
wer left corner of the window:
Connecting to localhost:33000
Connection established
Select the "Runtime" tab on the top left corner of the window. Click o
n "Debugger" and then again on "Classes." You should see a list of
all the classes that are currently loaded into Tomcat.
Point your browser to http://127.0.0.1:yourPortNumber/csc309/servl
et/HelloWorld
Go back to NetBeans, the class HelloWorld should have been adde
d to the list of available classes.
Double click on HelloWorld.
NetBeans Interface
Set Netbeans
Q and A
Tomcat System
Directory Structure
Bin – Startup/shutdown scripts and other useful files.
Conf – Configuration files, including modules.xml, serv
er.xml, and a number of apps-<name>.xml.
Logs – event log file for each day
Webapps – web application files
Work -- intermediate files (such as compiled JSP files)
during its work. If you delete this directory while Tomc
at is running you will not be able to execute JSP page
s!
Sysdeo Eclipse Tomcat Launcher plug
in
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.xml file)
Adding Java Projects to Tomcat classpath
Setting Tomcat JVM parameters, classpath and bootclasspath
Exporting a Tomcat project to a WAR File
Choosing Tomcat configuration file
Capability to use a special Tomcat classloader to have classes in
several java projects loaded at the same classloader level than cl
asses in a Tomcat project, see readmeDevLoader.html (Thanks
Martin Kahr)
Setup Tomcat
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 director
y
Add a new user
scroll down the menu point "Tomcat" and click the item "To
mcat Manager App"
add a username and a password
click on "Add user to tomcat-users.xml"
Test Start Tomcat Server
HelloWorld Example
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 HelloServlet in the
directory WEB-INF/src
create the file web.xml in the directory WEB-I
NF (Note: not in WEB-INF/src!!!)
Start browser
"http://localhost:8080/HelloWorld/hello"
HelloServlet
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class HelloServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOEx
ception {
PrintWriter out = 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>