Debugging inside a JSP page?

折月煮酒 提交于 2019-12-08 11:22:13

问题


I'm using Java 1.6, Spring 3.4, Spring Webflow 2.3.2 and Tomcat 7. I'm trying to debug a JSP page which uses EL expressions like:

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

The myObject object is passed in as the Webflow model object. I have a breakpoint set on this line and I am able to reach it and break on it, but 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 the heck can I find this model object? What is it contained in by the time it reaches the JSP page?


回答1:


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

If you are using a debugger, like the one in Intellij (which I use), 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 somebody.




回答2:


In IDEA 2016.2 request in JSP debug doesn't work anymore:(

It is possible to get attribute as

_jspx_page_context.request.getAttribute("...")

(inside tag as parentTag.requestContext.request.getAttributeNames())

It's also possible add in project dependency on jasper with provided scope:

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>jasper</artifactId>
        <version>6.0.47</version>
        <scope>provided</scope>
    </dependency>

and use auto completion:



来源:https://stackoverflow.com/questions/21977567/debugging-inside-a-jsp-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!