Bug Hunting - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Bug Hunting

Description:

Whenever you come across an error in your web application, you need a mental ... You only put apostrophes around values that are string-based and your database ... – PowerPoint PPT presentation

Number of Views:507
Avg rating:3.0/5.0
Slides: 17
Provided by: yc0578
Category:

less

Transcript and Presenter's Notes

Title: Bug Hunting


1
Bug Hunting
  • Obviously, the best approach to reducing bugs is
    to code to a design and perform testing at
    incremental stages.
  • However when you dont know what the problem is
    then
  • Whenever you come across an error in your web
    application, you need a mental checklist to help
    you track down the problem.

2
Files and Folders
  • Your .htm, .jsp and database files should be
    placed in
  • At University
  • //trentdev/wwwdatajsp/OOSE/studentid/
  • At Home
  • /tomcat/webapps/ROOT/

3
Files and Folders
  • In the commercial world (or with a hosting
    company), these paths should be
  • .htm .jsp goes in /tomcat/webapps/ROOT/AppName/
  • Database depends! Access anywhere. Database
    folder?
  • /tomcat/webapps/ROOT/AppName/database/Access.mdb
  • SQL or other database server will be separate
    ask host! Use sqlyog etc.
  • Beans /tomcat/webapps/ROOT/AppName/WEB-INF/classe
    s

4
Files and Folders
  • Your bean .class files should be placed
  • At University
  • //trentdev/wwwdatajsp/OOSE/studentid/WEB-INF/class
    es
  • At Home
  • /tomcat/webapps/ROOT/AppName/WEB-INF/classes/

5
HTML Checklist
  • Ensure the server is installed correctly and has
    been started.
  • Are you using the correct URL (should start with
    http//)
  • Are your .htm files appearing ok
  • Do any of your HTML forms contain reserved Java
    keywords as names (e.g. not String, int etc.)
  • Do any of your HTML forms contain reserved SQL
    keywords (e.g. name, description etc.)
  • http//www.xlinesoft.com/asprunnerpro/articles/sq
    l_access_odbc_reserved_keywords.htm

6
JSP Checklist
  • Remember that using GET you are restricted to
    1024 chars.
  • You should use POST but GET is good for
    debugging.
  • Use the error page material from last week!
  • If you are getting a syntax error when the page
    loads and the Java error message isnt
    particularly helpful then you could try opening
    the page in Eclipse (www.eclipse.org) which gives
    possible solutions.

7
Java Bean Checklist
  • When you develop your bean, first check that you
    can pass data to and from your JSP before doing
    anything else!!!
  • This will check the basic setup of the bean.
  • Remember that the names you chose for the HTML
    form elements should be mirrored in the bean
    attributes.
  • If you dont do this then the mechanism for
    passing data using the general setProperty wont
    work
  • ltjspsetProperty name"Guests" property""/gt

8
Java Bean Checklist
  • The names for your get and set methods should
    match the attribute names in your bean.
  • e.g. private String username
  • public String getUsername() return username
  • public void setUsername(String username)
    this.username username
  • Use the exception handling methods from last
    week!
  • Your package name on the University server should
    be whatever you called it in your Java source
    file.

9
Java Bean Checklist
  • Assuming you can pass information to and from the
    JSP page and the Bean and the bean compiles then
    do the following
  • Copy the code for the method that doesnt work
    from your bean and put it into your JSP where the
    call to the method is made.
  • Comment out the call to the bean method.
  • Instead of passing the data to your bean via
    setProperty, get the data via getParameter and
    use this data in your new JSP method.
  • This circumvents the bean code and lets you check
    the method directly.

10
Java Bean Extra
  • If you are using another class (bean or standard
    Java) in your bean code and you are getting
    compilation errors because your bean cannot find
    the other code then
  • javac classpath c\tomcat\webapps\ROOT\AppName\WE
    B-INF\classes MyBean.java
  • If you use Eclipse then this should handle all of
    this automatically (even without restarting the
    server!)

11
Caching Problems
  • Make sure that in your browser, you have turned
    off page caching In IE, Tools?Internet
    Options?Settings
  • Then make sure it is set to
  • Every visit to the page (not automatic etc.)
  • Then delete all of the current browser cache by
    pressing the Delete Files button and selecting to
    delete all offline content, then hit OK.
  • Now retry the page in your browser.

12
Caching Problems
  • Even the latest version of Tomcat appears to
    occasionally fall foul to the dreaded caching
    bug.
  • Typically, your JSP or bean code has an error in
    it.
  • You put in a fix for the error and press CTRLF5
    in the browser but you get the same error
    message.
  • To ensure that Tomcat is using the latest version
    of your work you can try the following

13
Caching Problems
  • You can force Tomcat to recompile your entire
    application by deleting the contents of the
    following folder
  • /tomcat/webapps/ROOT/work/
  • Only do this after you have shutdown the server
    or some files may not get deleted!
  • Do not delete the work folder itself however.

14
Database Problems
  • Remember we are using DSN-less connections.
  • Your connection object must have the following
    structure
  • At University
  • Connection conn DriverManager.getConnection("jdb
    codbcDriverMicrosoft Access Driver
    (.mdb)DBQ//trentdev/wwwdatajsp/OOSE/studentid/
    databasefilename")
  • At Home
  • Connection conn DriverManager.getConnection("jdb
    codbcDriverMicrosoft Access Driver
    (.mdb)DBQC/tomcat/webapps/ROOT/databasefilena
    me")
  • OR, you can use the IP address of your machine
    (127.0.1.2 in this example)
  • Connection conn DriverManager.getConnection("jdb
    codbcDriverMicrosoft Access Driver
    (.mdb)DBQ//127.0.1.2/databasefilename")

15
Database Problems
  • Instead of having to have two versions of your
    connection code (one for Uni and one for home),
    you could do the following
  • try
  • Connection conn DriverManager.getConnection("jd
    bcodbcDriverMicrosoft Access Driver
    (.mdb)DBQ//trentdev/wwwdatajsp/OOSE/yc1/Guestb
    ook.mdb")
  • catch(SQLException sqlex)
  • Connection conn DriverManager.getConnection("jd
    bcodbcDriverMicrosoft Access Driver
    (.mdb)DBQC/tomcat/webapps/ROOT/Guestbook.mdb
    ")

16
Database Problems
  • Be very careful with your SQL statements!
  • Remember that you cannot put a record into a
    database that has the same primary key value as
    another record.
  • You only put apostrophes around values that are
    string-based and your database field is expecting
    Text values. E.g.
  • INSERT INTO MyTable (4157, Yvan Cartwright,
    LC24)
  • Not this if the first field in the table is
    numeric!
  • INSERT INTO MyTable (4157, Yvan Cartwright,
    LC24)
  • If you have a problem with currency fields, use
    number, set its field size to Decimal and set
    the format to Currency, then set the number of
    decimal places to 2.
Write a Comment
User Comments (0)
About PowerShow.com