Take the 2-minute tour ×

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.


share|improve this question
may be asked on Stackoverflow.com –  Kugathasan Abimaran Jan 27 '11 at 16:50
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. –  ampersandre Jan 27 '11 at 17:01
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 '11 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 '13 at 11:35
add comment

2 Answers

up vote 11 down vote accepted

There are several options that can help you:

  1. This answer actually explains how to debug JSPs specifically: http://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 folder and search for test_jsp.java (once you find the right folder, you'll see that the folder structure matches your JSP folder 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.

share|improve this answer
+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 –  bunglestink Jan 27 '11 at 17:01
Thanks! Option 4 is ideal, I agree, but we don't have great view/controller separation in this project. –  ampersandre Jan 27 '11 at 17:05
+1 for item #4. Absolutely important. –  Chiron Jun 2 '11 at 22:48
add comment

Debugging JSP is same as debugging a java file. We can set breakpoints where ever necessary in a JSP page in netbeans, I have tried that in netbeans 6.9.1

share|improve this answer
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. –  GlenH7 Mar 5 '13 at 11:57
add comment

Your Answer


