1.5. Try Some Simple HTML and JSP Pages

After you have verified that the server is running, you should make sure that you can install and access simple HTML and JSP pages. This test, if successful, shows two important things. First, successfully accessing an HTML page shows that you understand which directories should hold HTML and JSP files. Second, successfully accessing a new JSP page shows that the Java compiler (not just the Java virtual machine) is configured properly.

Eventually, you will almost certainly want to create and use your own Web applications (see Chapter 4, “ Using and Deploying Web Applications ”), but for initial testing I recommend that you use the default Web application. Although Web applications follow a common directory structure, the exact location of the default Web application is server specific. Check your server’s documentation for definitive instructions, but I summarize the locations for Tomcat, JRun, and ServletExec in the following list. Where I list SomeDirectory you can use any directory name you like. (But you are never allowed to use WEB-INF or META-INF as directory names. For the default Web application, you also have to avoid a directory name that matches the URL prefix of any other Web application.)

  • Tomcat Directory

    install_dir/webapps/ROOT

    (or install_dir/webapps/ROOT/SomeDirectory)

  • JRun Directory

    install_dir/servers/default/default-app

    (or install_dir/servers/default/default-app/SomeDirectory)

  • ServletExec Directory

    install_dir/public_html [1]

    [1] Note that the public_html directory is created automatically by ServletExec the first time you run the server. So, you will be unable to find public_html if you have not yet tested the server as described in Section 1.4 (Test the Server).

    (or install_dir/public_html/SomeDirectory)

  • Corresponding URLs

    http://host/Hello.html

    (or http://host/SomeDirectory/Hello.html)

    http://host/Hello.jsp

    (or http://host/SomeDirectory/Hello.jsp)

For your first tests, I suggest you simply take Hello.html (Listing 1.1, Figure 1-6) and Hello.jsp (Listing 1.2, Figure 1-7) and drop them into the appropriate locations. The code for these files, as well as all the code from the book, is available online at http://www.moreservlets.com. That Web site also contains updates, additions, information on short courses, and the full text of Core Servlets and JavaServer Pages (in PDF). If neither the HTML file nor the JSP file works (e.g., you get File Not Found—404—errors), you likely are using the wrong directory for the files. If the HTML file works but the JSP file fails, you probably have incorrectly specified the base JDK directory (e.g., with the JAVA_HOME variable).

Figure 1-6. Result of Hello.html.


Figure 1-7. Result of Hello.jsp.


Listing 1.1. Hello.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD><TITLE>HTML Test</TITLE></HEAD> 
<BODY BGCOLOR="#FDF5E6"> 
<H1>HTML Test</H1> 
Hello. 
</BODY> 
</HTML> 

Listing 1.2. Hello.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD><TITLE>JSP Test</TITLE></HEAD> 
<BODY BGCOLOR="#FDF5E6"> 
<H1>JSP Test</H1> 
Time: <%= new java.util.Date() %> 
</BODY> 
</HTML> 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.68.28