O'Reilly logo

Harnessing Hibernate by James Elliott, Ryan Fowler, Timothy M. O'Brien

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create the Web Application

Now that you’ve got a running Tomcat instance, the next step is to create a web application. We’ll start by creating the directory structure for our web application inside your project directory, as demonstrated in Example 14-2, so you can start with that directory if you created it by hand, or you can download the code examples from the book’s web site.

Example 14-2. Command to create the web application structure

            $ 
            mkdir -p webapp/WEB-INF
          

To get started, lets put a web.xml and an index.jsp in our application so we can get something deployed. Every J2EE web application needs a web.xml file, so we’ll start there. Later on we’ll fill this file out with Filters and Servlets, but for now we’re going with a bare bones web.xml in webapp/WEB-INF, like the one shown in Example 14-3.

Example 14-3. A minimal webapp/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
</web-app>

A web application isn’t much to look at without at least one view, so we’ll start with a very basic index.jsp file in our application’s root directory, webapp/. Again, we’re not going for style points just yet; we just need something there so that we’ll know when things are working. The code shown in Example 14-4 will do the trick.

Example 14-4. A basic JSP in webapp/index.jsp ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required