Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

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 18 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
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 – Peter Perháč Jun 20 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:

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. – gnat May 6 at 8:58

protected by gnat May 6 at 8:57

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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