Accessibility

TechNote

Debugging JSP pages

Debugging Methods
There are several different approaches to choose from when debugging JSP pages. For example, the error.jsp page can be used to capture runtime exceptions. However, other methods of debugging are also available. In some cases, a different strategy may prove to be more useful.

error.jsp
Exceptions originate from problems in a compiled JSP file. Finding these helps determine the location of problems within a JSP page. When an error.jsp file is created, the directiveisErrorPage is set to true. Setting the directive equal to true gives the page access to the exception object which contains a reference to the runtime exception(s).

To create an error-handling file for JSP, do the following:

  1. In any text editor, create a plain text (ASCII) file called error.jsp.
  2. Type the following code in the file:
     <%@page  isErrorPage="true"%><% //Put your error-handling code here %> 

    For example, the error-handling code could be an exception object:
    out.println(exception.getMessage());

  3. Save the file. Place it in your site's local root folder, to be uploaded to your JSP server with the rest of the site files.
  4. The page directive must be added to the pages in the application.

To add the errorPage attribute to the page directive in existing JSP pages:

  1. Open the page in Dreamweaver and choose View > Code.
  2. Look for the page directive at the top of the page. It will look something like:

    <%@page import="java.sql.*"%>

    Note: If the page directive does not exist, it can be manually added.

  3. Add the errorPage attribute to the directive, specifying the document relative or application relative error page path.

    For Example:

    <%@page import="java.sql.*" errorPage="error.jsp"%>

  4. Save the document.

Stacktrace
Frequently, better diagnostic information can be obtained when an error.jsp file is not used. When a JSP fails, almost all JSP engines will display the error and the complete stacktrace. This identifies the JSP methods that were called. Some configurations also identify the line where the code failed. This is very useful for debugging purposes. Having an error page during debugging means that only the error messages that are contained in the exception object will be displayed. An error.jsp can best be utilized at the end of creating the final application- not for debugging, but rather to present a pleasant report to the visitor when a page fails. Usually, the error.jsp page includes general information, the error message and an e-mail link to the webmaster of the site.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_14500
OS:Windows (All)
Mac OS (All)

Products Affected:

dreamweaver