Chapter 14: JSP Debugging - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Chapter 14: JSP Debugging

Description:

How a change in code or data might affect the observation. Test ... org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp ... – PowerPoint PPT presentation

Number of Views:157
Avg rating:3.0/5.0
Slides: 13
Provided by: conest
Category:

less

Transcript and Presenter's Notes

Title: Chapter 14: JSP Debugging


1
Chapter 14 JSP Debugging
Reference Beginning JSP
2
Objectives
  • Debugging Art or Science?
  • Debugging Techniques
  • Compile Time Bugs
  • Console Output
  • Log4J
  • Debugging with Tools
  • NetBeans 4.1 JSP Debugger

3
Debugging Art or Science?
  • Pages 436-437
  • Science of Debugging
  • Observation
  • Program does not work as expected
  • Hypothesis
  • Guess what causes the unexpected behavior
  • Prediction
  • How a change in code or data might affect the
    observation
  • Test
  • Test the prediction by making the change and
    observing new results

4
Compile Time Bugs
  • If JSP fails to compile
  • Servlet container often returns a message to the
    browser explaining the problem
  • In NetBeans 4.1, compile time bugs are caught
    when JSP page is compiled
  • Example
  • lt_at_taglib prefix"c" uri"http//java.sun.com/jsp/
    jstl/bore" gt
  • In Netbeans 4.1
  • Build Compile Example1.jsp shows
  • org.apache.jasper.JasperException The absolute
    uri http//java.sun.com/jsp/jstl/bore cannot be
    resolved in either web.xml or the jar files
    deployed with this application

5
Debugging Scriptlets in JSP
  • Pages 439-441
  • In NetBeans 4.1
  • Build Compile Example2.jsp
  • Result Cannot find symbol
  • symbol class Random
  • location class org.apache.jsp.Example2_jsp
  • Random r new Random()
  • Solution Add import statement
  • lt_at_page import"java.util.Random" gt

6
Instrument JSP Code
  • Pages 442-444
  • Using System.out.println
  • Very basic, difficult to disable, etc.
  • Run Example3.jsp and Example4.jsp
  • Results logged under Output tab
  • Bundled Tomcat 5.5.7

7
Servlet Container Logging System
  • Pages 445-446
  • Using the ServletContext.log()
  • No control which messages to log
  • Run Example5.jsp
  • lt String message
  • this.log( message )
  • gt

8
Logging with JDK Logger
  • Pages 447-454
  • Using the Logger.info() depending on the logging
    level
  • Set the level in ltJAVA_HOMEgt/jre/lib/logging.prope
    rties
  • globally configured
  • E.g., org.apache.jsp.level INFO

9
Logging with Log4j
  • Pages 454-460
  • Advantage
  • Log4j JAR can be deployed as part of an
    application
  • not globally configured
  • Set the level in WEB-INF /classes/log4j.properties

10
Logging with Log4j and Tag Libraries (Scriptless
JSP)
  • Pages 460-464
  • Unlike previous approaches, does not require
    scriptlets in JSP
  • E.g., http//localhost8084/ch14/LogTags.jsp

11
Debugging with Tools
  • Using NetBeans 4.1
  • Set breakpoints
  • Examine variables
  • Step through code
  • Step Over, Step Into, Step Out, Continue,
    Terminate
  • Remote debugging
  • Attach to port 8084 (default)

12
Next Steps
  • Try It Out sections of Textbook (Chapter 14)
  • Examples 1 to 7
  • LogTags.jsp
  • You can skip the rest of the examples and
    exercises
Write a Comment
User Comments (0)
About PowerShow.com