How do I evaluate objects when debugging a JSP?

I am a relatively experienced Java programmer and IntellJ user and I am trying something new - I need to debug a web app on Tomcat.   However, there doesn't seem to be a clear-cut guide to how to do this in Intellj (at least I can't find it.)

I've got the project running in debug mode, set a breakpoint inside my JSP and when I hit that page my app stops at the breakpoint.

My question:   How do I evaluate the values that the JSP is using?   I am breaking on a line like:

    <c:if test="${myObject.myThing == SomeClass.ENUMVALUE.myvalue}"  >

and anything I try to "watch" or "evaluate" gives me an error message.   I get either

${myObject.myThing == SomeClass.ENUMVALUE.myvalue}:  Invalid Expression

myObject.myThing:  Type is unknown for 'myObject'

(MyCorrectType) myObject:  Cannot find local variable 'myObject'

How can I evaluate these expressions and find out what's in them?   Is that even possible?

3 comments

Hello.

I've tried to evaluate such "predefined" object as pageContext, and it works for me.

Then where does myObject come from? How is it defined?

Regards,
Alexander.

0

the "myObject" object is passed in from the Spring WebFlow servlet (I think).   It is defined as the "model" object backing a Spring form.   I know that it is there because I'm modifying an existing page which uses this thing all over the place.   I just can't figure out how to stop the page and look at the object.    In the debug window I see 4 or 5 objects, one of which is "pageContext".   I've tried drilling down into the page context looking for this attribute but no idea where it is.  

I should say this probably is not an Intellij specific question, more like a general Tomcat question (perhaps) or even a Spring question.   If you think another forum would be appropriate feel free to redirect me.   I was just hoping to find someone with specific experience in Intellj.   

Thanks -

0

The answer turned out to be that it will be in the "request" object (In my particular case, it was buried several levels deep inside wrapper objects.)

If you are using the Intellij debugger you can get the value of an individual attribute (like the Webflow model object) by evaluating the expression

request.getAttribute("attributeName")


Note that this may return a Java Object type, and you may have to cast it to the correct type.

For example, in my case, I was able to find the value of the value I wanted using this expression:

((MyObject)(request.getAttribute("myObject"))).getMyThing()

I hope this helps other people!

0

Please sign in to leave a comment.