Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 – Abimaran Kugathasan Jan 27 '11 at 16:50
Ok. Sorry, I'm not entirely clear on the difference between and 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
One technique is seeing compile… – sᴜʀᴇsʜ ᴀᴛᴛᴀ Aug 4 '14 at 12:59
up vote 16 down vote accepted

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.

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: – 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
Also +1 for item #2. I had no idea where to find the * classes. – Scott Scooter Weidenkopf Sep 28 '15 at 16:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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