How can I debug a JSP?

by ampersandre   Last Updated May 06, 2016 08:02 AM

I'm trying to edit a JSP for a project and I'm getting a NullPointerException somewhere in the JSP when it's requested from my server.

My web server (JBoss) is reporting the exception, but it's giving me a bogus line number. It's reporting that the exception happened on line 702, but my JSP is only 146 lines long, so I'm unable to identify which line is choking.

What are some good techniques to debug errors in JSPs? I'm using IntelliJ 9 Ultimate as my IDE.


Answers 2

There are several options that can help you:

  1. This answer actually explains how to debug JSPs specifically: I haven't ever tried this so I followed the next three suggestions when I was using JSP, JBoss, and IntelliJ...

  2. Remember that JSPs are compiled to classes. When it says line 702, it means in the compiled class. If you have test.jsp, the class name is probably test_jsp, so open your JBoss work directory and search for (once you find the right directory, you'll see that the directory structure matches your JSP directory structure). Whenever I had a JSP exception I could find the line quite easily and usually match it up to the corresponding line in the JSP.

  3. Breakpoints work just fine in Java classes called from a JSP. So, maybe you can move the Java script code that you have in your JSP into a class and debug from the entry point. In the future you can also make a habit of rearranging your logic so that the majority of it is in a class that is being called from the JSP, and the JSP is simple, straightforward and hopefully not throwing any exceptions. This is good practice anyway.

  4. Better yet, remove all (or virtually all) Java logic into Java classes, leaving JSPs for HTML and JSP tags. I know this isn't feasible right away, but again, it's a good idea long term to avoid problems like this.

January 27, 2011 16:51 PM

You can debug a JSP page easily just like a java code:
"a JSP file is the same like debugging a Java class, but the most features (Watch, Inspect, etc) are not implemented. The only way to get the values of variables is the Variables view."
See the link below:

May 06, 2016 07:39 AM

Related Questions

Comparing runtime flows when hunting for a bug

Updated October 09, 2016 09:02 AM

Write xtend code with IntelliJ Idea

Updated May 14, 2015 09:02 AM