52

Does anyone know of a good tool for debugging JSPs from within Eclipse? I'd like to be able to set and watch breakpoints, step through the Java code/tags, etc within Eclipse while the app is running (under JBoss in my case).

Presumably, it's reasonably straightforward to debug the servlet class that's generated from a JSP, but it's also fairly unappealing.

Dónal
  • 185,044
  • 174
  • 569
  • 824
  • Man, I could've used this a few months ago on a project. I thought JSP debugging wasn't possible. – Owen Sep 23 '08 at 20:08

4 Answers4

25

If you have WTP installed, you can set breakpoints within a JSP and they work fine in a regular "remote debug" session. However, once you've stopped on a breakpoint, stepping through the code is nigh on impossible and finding whatever it is that you wish to inspect takes a lot of digging around in the "Variables" view.

Dónal
  • 185,044
  • 174
  • 569
  • 824
  • It doesn't let you create a new "Remote Java Application" in Eclipse 4.6.2 with WTP installed. The button does nothing. Also breakpoints don't work in JSPs as described here https://stackoverflow.com/questions/53915010/breakpoints-not-working-on-jsp-pages-in-eclipse – Philip Rego Dec 24 '18 at 15:19
  • @PhilipRego They do partially work at least in my environment (2023-03). However they won't work on some lines. If you run "Toggle breakpoint" on a line which has nothing but HTML, your command is silently ignored. You need to see a blue breakpoint appear for it to work. – Philippe Cloutier Jun 08 '23 at 18:07
  • The cursor is broken. Sometimes, it disappears even while stepping continues, so you need to go slowly, relying heavily on "Show method result after a step operation", to keep following where you're at until the cursor comes back. – Philippe Cloutier Jun 08 '23 at 18:08
2

If you are having to use a debugger in a JSP, chances are very good that you are doing things in the JSP that you shouldn't be. I recommend that you think very hard about whether your current implementation is using good MVC design practice. JSPs really should be about presentation, which should rarely (if ever) require debugging.

If you have certain logic constructs that you are having to implement in JSP, consider implementing them using a custom tag (which is easy to debug in an IDE), or do the processing in controller servlet that presents the data in an easy to digest form for the JSP.

Kevin Day
  • 16,067
  • 8
  • 44
  • 68
  • 40
    How do you know @Don is doing anything but debugging atm? How do you know he/she isn't debugging legacy code? – jyoungdev May 23 '12 at 10:44
  • 30
    A colleague of mine (looking to debug a JSP) commented on this answer when I sent him a link to the question: 'It's like "Quick - I need to get a fishhook out of my eye" "How did you get a fishhook in your eye? That's really not the kind of thing you should do with a fishhook..."' – CupawnTae Dec 13 '12 at 21:26
  • 4
    @apollodude217 perhaps it was the "step through the Java code" line in his question? I certainly realize that my 'answer' is not what the OP was specifically asking about, however I find that the "hey, maybe you should re-think your approach" answers are the ones that help me become a better developer. I very rarely learned things in any of my uni classes when the instructor answered students questions literally. The real learning happened in the conversational side alleys that arose when the prof asked the student to think hard about *why* they were asking the question. – Kevin Day Dec 17 '12 at 03:50
  • 6
    completely disagree - for example I have to debug JSP's because I have a big legacy jsp's codebase. I didn't create this code, this solution, just need to debug it, nothing else. – nahab Dec 24 '13 at 14:41
  • 2
    Chances are indeed high that he's doing something wrong. He wants to debug the JSP because he's not sure exactly what it is he's doing wrong. That's why he wants to debug. Even within a rigid MVC framework, you still need to see exactly where something is failing, or to explain which path of an "if" is being taken. – Menachem Nov 25 '15 at 21:44
  • 1
    This is a comment, not a solution. Lot of upvotes on an opinion based answer. – Christopher Schneider Mar 10 '16 at 19:17
  • The answer is "Does anyone know of a good tool for debugging JSPs from within Eclipse?" NOT "Do you think is a good practice to put logic in jsp?" Maybe it's a big old project and you he can't update it in the (good) way you said. – Paolo Biavati Jun 16 '22 at 09:58
2

Within Eclipse, you can put breakpoints to your jsp file, step through the Java code/tags, etc.
However the only view you can use while debugging is the Variables view to inspect the value of any variable.

And one more thing, you can not see the value for example of this expression:
<%= response.encodeURL("ProcessLogin.jsp") %>
just the value of the variable response.

Esteban
  • 162
  • 8
0

Apparently, Eclipse has a troubleshooting page on this, though when I tried it I did get a 404 with it. Hopefully this can at least get you started in a good direction.

Tracey
  • 9
  • 1
  • 1
  • 2
  • This doesn't work. https://stackoverflow.com/questions/53915010/breakpoints-not-working-on-jsp-pages-in-eclipse – Philip Rego Jan 04 '19 at 18:25