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.


  • 1
    may be asked on Stackoverflow.com Jan 27, 2011 at 16:50
  • 1
    Ok. Sorry, I'm not entirely clear on the difference between StackOverflow.com and Programmers.StackExchange.com. I'm not sure which questions belong where.. I've read the FAQ for programmers.stackexchange but it's a little vague. Jan 27, 2011 at 17:01
  • 3
    Actually I'm not sure that this would be OK on Stack Overflow. While it's fairly specific there's not enough concrete detail (due to the nature of the problem). What you are after is debugging techniques which should be on topic for this site.
    – ChrisF
    Jan 27, 2011 at 17:05
  • have you included any jsps inside your jsp ? That's how the line number may increase . Question need to be moved to stackoverflow
    – minusSeven
    Mar 5, 2013 at 11:35
  • One technique is seeing compile files:codeinventions.blogspot.com/2014/08/… Aug 4, 2014 at 12:59

2 Answers 2


There are several options that can help you:

  1. This answer actually explains how to debug JSPs specifically: https://stackoverflow.com/questions/33739/jsp-debugging-in-intellij-idea. 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 test_jsp.java (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.

  • 3
    +1 for removing logic from the JSP. More on this can be seen in the JSP/Servlet best practices, with Model 2 (MVC) architecture: oracle.com/technetwork/articles/javase/servlets-jsp-140445.html Jan 27, 2011 at 17:01
  • Thanks! Option 4 is ideal, I agree, but we don't have great view/controller separation in this project. Jan 27, 2011 at 17:05
  • 1
    Also +1 for item #2. I had no idea where to find the *_jsp.java classes. Sep 28, 2015 at 16:34
  • 2
    removing all logic from JSPs on a project that has thousands of JSPs, each containing several thousand lines of scriptlets... no, thanks, just want to debug the Hashtables and Vectors. FML :-( </rant> nice answer though Jun 20, 2016 at 8:17

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:

  • 4
    When answering an older question that already has a well received answer, please add more detail to your answer so that you are addressing something that wasn't already covered.
    – gnat
    May 6, 2016 at 8:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.