Home > Articles

Getting Started

  • Print
  • + Share This
This chapter is from the book

Creating Web Documents

Throughout this book, we'll be creating our own documents—HTML documents, Java documents, JSP documents, and so on. That means that we'll need an editor that can save plain text files as part of our development environment.

You can use any editor or even word processor you like, such as WordPad in Windows, or vi (or even pico) in Unix. The main point here is that you must save the files you create in plain text format (not, for example, rich text format, which is the default for some versions of WordPad).

For example, you can see how to use WordPad to create a Web page named ch01_01.html (that is, Example 1 from Day 1) in Figure 1.6. When you save it, use the File, Save As menu item, and select the Text Document item in the Save As Type box of the Save As dialog box that appears. We'll see how to open this new HTML document in Tomcat later in this Day.

Figure 1.6 Creating a Web page.

TIP

When we develop JSP-enabled pages, we'll give them the extension .jsp, like index.jsp. When you save a file with the extension .jsp in WordPad, it'll try to add the extension .txt because it doesn't know about the .jsp extension, giving you index.jsp.txt. To avoid this, put quotation marks around the name of the file when you save it—if you save the file as "index.jsp", you'll get the file index.jsp, not index.jsp.txt.

You can find the HTML page created in Figure 1.6 in Listing 1.1.

Listing 1.1 A Simple Web Page (ch01_01.html)

<HTML>
  <HEAD>
    <TITLE>
      A Web Page
    </TITLE>
  </HEAD>

  <BODY>
    Hello there!
  </BODY>
</HTML>

Where can you save this document so you can view it with Tomcat? In this book, it'll be easiest to store the examples from Day 1 in a directory named ch01, the examples from Day 2 in ch02, and so on. Those directories are subdirectories of the webapps directory in the Tomcat directory structure:

jakarta-tomcat-4.0.3
|__webapps
  |__ch01
  |__ch02
  |__ch03
    .
    .
    .

Create the ch01 directory now—for example, you can use the Windows Explorer in Windows for this purpose. We'll also need a WEB-INF directory under ch01, as well as classes and lib subdirectories (even though they're empty):

jakarta-tomcat-4.0.3
|__webapps
  |__ch01
    |__WEB-INF
       |__classes
       |__lib
  |__ch02
    |__WEB-INF
       |__classes
       |__lib

Create this directory structure for ch01 now, and save the first example, ch01_01.html, in ch01 (that is, in jakarta-tomcat-4.0.3\webapps\ch01 in Windows, or jakarta-tomcat-4.0.3/webapps/ch01 in Unix).

What's the URL of our new document? If we had put it into the webapps directory itself, it would be http://localhost:8080/ch01_01.html, but because we've placed it in the webapps\ch01 directory, its URL is http://localhost:8080/ch01/ch01_01.html. Enter that URL into the browser now, and you should see the result in Figure 1.7.

Figure 1.7 Viewing a new document in Tomcat.

And that's it—now our development environment is complete. We've got Java, we've got a JSP server, we've got a browser, and we've got an editor with which to write our Web documents (alternatively, you could just download the source code for this book and use that). Not bad—we've made a great deal of progress.

Now we're ready to start working up to JSP itself. And to do that, it's a good idea to start by taking a look at the history of JSP.

  • + Share This
  • 🔖 Save To Your Account