Developing Web Applications With Ant by Richard Hightower - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Running the Web Application

Now that we've built and deployed the Web application project, let's run it. We start our servlet engine and then open the site in our browser--for example, http://localhost/hello/HelloWorldServlet. (Tomcat's default setup is port 8080, so you may have to adjust the URL.)

You may notice a couple of things. The application URL is defined in a directory called hello (http://localhost/hello/HelloWorldServlet). By default, Tomcat unjars our WAR file in a directory called <War file File Name>.

The HelloWorldServlet part of the application's URL is defined by a mapping in the deployment descriptor:

<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>xptoolkit.web.HelloWorldServlet</servlet-class> <init-param>

<param-name>Greeting.class</param-name>
<param-value>@Greeting.class@</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/HelloWorldServlet</url-pattern>

</servlet-mapping>

The servlet tag declares the servlet and gives it a name. The servlet mapping assigns HelloWorldServlet the URL pattern /HelloWorldServlet. We could change the URL pattern to /PeanutButter, and the URL http://localhost/hello/PeanutButter would work.

Actually, we mapped the 404 error to HelloWorldServlet as well, so the server sends any URL it does not recognize to HelloWorldServlet to process (for the benefit of people with fumble fingers...not a good idea for a production system).

The next section describes a simple applet project that integrates with the Web application project.