|[ Team LiB ]|
Compile Versus Runtime Errors
Problems with JavaServer Pages can appear during compilation or runtime. Because you compile your own servlets, servlet problems appear only at runtime. You may recall from Hour 5, "JSP and Servlet Lifecycles," that a JSP goes through translation and execution phases. During translation, a container inspects and validates a JSP and then locates or creates an implementation. In most containers, this produces a Java source file and its corresponding servlet class. In most cases, a JSP is compiled when it is first invoked. However, a container can compile a JSP when it is deployed, or it can be compiled as part of a build process using Ant and the Tomcat precompiler, jspc.
Let's look at two of the most common problems that occur during translation. Figure 11.1 shows the result of misspelling the page directive.
If you look at the exception produced, the problem is easily identified by the phrase "Invalid Directive." The container even provides the line and column numbers (in parentheses following the name of the JSP file) where it believes the problem occurred.
To illustrate an error that occurs while generating the servlet class, the second example attempts to invoke a method from an object that does not exist. Figure 11.2 presents the error page.
Once again, the report is very informative. In most cases, Tomcat is good at identifying the problem or at least putting you pretty close to it.
Unfortunately, troubleshooting runtime errors is almost always more difficult. Here, servlets and JSPs begin to look alike from a debugging perspective. Runtime errors are usually the result of programming mistakes. If you're lucky, you'll get an exception that will help you. In other cases, you'll stare at a blank screen or ponder some peculiar behavior. For these, you have to roll up your sleeves and go to work.
|[ Team LiB ]|