Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve Spring model variables in a JSP when debugging with IntelliJ IDEA?

I've set a breakpoint in a JSP when running a Tomcat application through IntelliJ IDEA (Ultimate ed.). So far so good, I can step through the JSP as expected.

The problem is: I am unable to resolve Spring model variables such as ${path} when debugging. Evaluate Expression triggers an error: "Cannot find variable 'path'".

As a workaround I can explicitly reference the model value with <c:set var="testPath" value="${path}">. That way I can see testPath in Variables » _jspx_page_context » attributes, but not path.

like image 406
neu242 Avatar asked Mar 24 '15 07:03

neu242


People also ask

Can we debug JSP in IntelliJ?

I did some tests and it seems to be possible to "influence" the behaviour of the IntelliJ Debugger. By this it is probably possible to implement debugging functionality for JSPs.

Can we put breakpoint inside JSP?

Set a Breakpoint Workshop extends the Eclipse debugger to allow you to debug JSP code. To set a breakpoint: Right-click in the gutter of the Source view and select Toggle Breakpoints.


2 Answers

Variable path is part of the Spring Framework and is set as an attribute to the PageContext, there are only few ways of debbugging such variables.

For me the best solution is to add an expression to your Watches View: pageContext.findAttribute("path") or _jspx_page_context.findAttribute("path")

It doesn't matter, because both of them point to the same runtime object:

enter image description here

like image 145
aw-think Avatar answered Sep 28 '22 05:09

aw-think


This is only a work-around, and is certainly not best practices. However, if you need something quick and dirty, set another String var to your $path param. The debugger will be able to see that new variable at runtime.

like image 23
Japes Avatar answered Sep 28 '22 06:09

Japes