Chapter 10: Error Handling - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Chapter 10: Error Handling

Description:

Syntax errors in scripting elements will show up only when JSP is translated and ... org.apache.jasper.JasperException org.apache.jasper.runtime.JspRuntimeLibrary. ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 10
Provided by: conest
Category:

less

Transcript and Presenter's Notes

Title: Chapter 10: Error Handling


1
Chapter 10 Error Handling
Reference Beginning JSP
2
Objectives
  • Sources of Errors
  • Syntax / JSP Coding Errors
  • Translation-time Errors
  • Request-time Errors
  • Others Logical Errors, User data-entry Errors
  • Handling Errors
  • Using JTSL ltccatchgt action
  • Using JSP Error Page Mechanism

3
Syntax / JSP Coding Errors
  • Reference Pages 304-309, Example 1
  • Syntax errors in scripting elements will show up
    only when JSP is translated and compiled at
    request time.
  • Avoid using scripting elements in new JSP
    projects to lessen complexity of debugging
  • Example1\index.jsp
  • Wrong use of curly bracket
  • for int i0 ilt50 i
  • Sample Output
  • An error occurred at line 8 in the jsp file
    /example1/index.jsp Generated servlet error
    Syntax error on token "", ( expected

4
Errors in JSP Directives and Actions
  • Reference Pages 309-313, Example 2
  • Example2\index.jsp
  • Incorrect attribute for page directive caught at
    translation time
  • lt_at_page lang"java" gt
  • No such JSP page error for JSP action caught at
    request time
  • ltjspinclude page"nosuch.jsp" /gt
  • Sample Output
  • org.apache.jasper.JasperException
    org.apache.jasper.runtime.JspRuntimeLibrary.intern
    alIntrospecthelper(JspRuntimeLibrary.java359)

5
Handling Request-time Errors
  • 1. Using JTSL ltccatch var gt action
  • Catches any errors that occur in the JSP code
    residing within its body
  • If optional var attribute not specified, error is
    ignored
  • 2. Using JSP Error Page Mechanism
  • Specify the errorPage attribute within the page
    directive
  • Error-handling JSP page can be shared
  • Specify the isErrorPage attribute within the page
    directive

6
JTSL ltccatchgt Action
  • Catching exceptions will not automatically show
    the stack trace
  • Provide meaningful error message for user to act
    upon (e.g., Please call IT Support team)
  • Example4\index1.jsp (Exercise 1)
  • localerr variable is specified
  • Specific exception class java.lang.ArithmeticExcep
    tion is handled.
  • ltccatch var"localerr"gt
  • errgen.divideByZero
  • lt/ccatchgt
  • ltcif test"localerr.rootCause.class eq 'class
    java.lang.ArithmeticException'"gt
  • Do not divide by zero!
  • lt/cifgt

7
JSP Error Page Mechanism
  • Example4\index.jsp
  • lt_at_page errorPage"showerr.jsp" gt
  • showerr.jsp (General error-handling JSP)
  • lt_at_page isErrorPage"true" gt
  • Error pageContext.exception
  • URI pageContext.errorData.requestURI
  • Status Code pageContext.errorData.statusCode
  • Stack Trace pageContext.exception.stackTrace

8
General Error-handling JSP Example
9
Next Steps
  • Try It Out sections of Textbook (Chapter 10)
  • Example 1, 2, 4
  • Exercise 1
  • You can skip Example 3 and Exercise 2
Write a Comment
User Comments (0)
About PowerShow.com