
96 Developing Applications for J2EE Servers
Running your servlet or JSP with Tomcat
Running your servlet or JSP with Tomcat
Before you run your web application, you should configure web view options to control
how Tomcat is launched in the IDE. For more information, see “Configuring the IDE for
web run/debug” in the “Working with web applications in the JBuilder IDE” chapter of
Developing Web Applications.
Before you web run your servlet or JSP in JBuilder, you also need to create a runtime
configuration, set runtime properties for your project, and compile your servlet or JSP.
For complete information about these topics, see “Working with web applications in the
JBuilder IDE” in Developing Web Applications. Once you’ve completed these tasks,
you are ready to run your servlet or JSP.
To web run your servlet or JSP in JBuilder, right-click the servlet or JSP file in the
project pane and choose Web Run. The Web Run command runs your configuration in
Tomcat without debugging it. If your servlet runs from an HTML or SHTML file, right-
click that file and choose Web Run.
If the Web Run or Web Debug command is grayed out on the context menu for a
servlet or JSP, check the runtime configuration. To run a web application, you need to
create a runtime configuration with the server type selected as the current runner. That
server must support the JSP/Servlet service. To create a runtime configuration, see
“Creating a runtime configuration” in the “Working with web applications in the JBuilder
IDE” chapter of Developing Web Applications.
Note Applets cannot be web run or web debugged. This is because applets don’t have a
URL or a web context to run in. Additionally, applets run in a client browser as opposed
to a server. Typically, you run an applet in Sun’s AppletViewer or in JBuilder’s
AppletTestbed. For more information, see “JBuilder’s AppletTestbed and Sun’s
appletviewer” in the “Working with applets” chapter of Developing Web Applications.
Starting Tomcat
When you choose Web Run, JBuilder starts Tomcat, using:
■
The runtime configuration
■
The options set on Tools|Preferences|Web Run|Debug|Optimize
Messages are logged to the web server tab displayed in the message pane. HTTP
commands and parameter values are also echoed to this pane. The name of the tab
will reflect the name of the web server, for example “Tomcat” for the Tomcat web
server.
Stopping Tomcat
To stop Tomcat, click the Reset Program button on the web server tab. To start the
web server again and re-run your web application, click the Restart Program button
on the tab. You’ll usually follow these steps when you make changes to source code,
re-compile, and re-run. You don’t need to close the web server pane each time you
start the web server.
Note The first time you press the Reset Program button, it simply sends a command to the
server to shutdown. In particular, if you are trying to debug your web application’s
lifecycle event handlers, this would call the
Servlet.destroy() and
ServletContextListener.contextDestroyed() methods. If you’re not debugging, the
server will usually shutdown by itself in a few seconds. If you press the Reset Button a
second time, the server process is terminated immediately.
Comentarios a estos manuales