English 中文(简体)
How do I determine where a JSTL expression variable (pageContext attribute) originated in IDEA?
原标题:

We ve got an app that makes heavy use of JSTL expressions and custom taglibs, which means our pageContext attributes could have been set just about anywhere. How do I go about determining where they originated? Consider something like:

<c:out value="${ myObject[ SOME_KEY ] }" />

I need to know where myObject came from -- how did it make its way into the pageContext? I am using IDEA, so if there is a shortcut for determining that within the IDE, it would be most helpful.

EDIT:

I don t want to know about the scope, but in what physical file the attribute was actually set. Almost identical to the Find Usages... functionality in the right-click context menu of IDEA. If I m three includes deep into a JSP that might be using taglibs and templating, an attribute set within the pageContext could have been set just about anywhere. I would like to find usages and instances of that attribute.

问题回答

The ${myObject} basically resolves to jspContext.findAttribute("myObject") which searches for the attribute in respectively the page, request, session and application scopes and returns the first non-null value it finds.

How smart you can make an IDE, it cannot know beforehand (during build/compile) in which scope it is been set. There are too much factors (visible as well as invisible) which needs to be taken into consideration. The only reliable way to find this out is doing it programmatically by accessing the desired scopes explicitly during runtime:

"myObject" is in:
<br>Page scope? ${not empty pageScope.myObject}
<br>Request scope? ${not empty requestScope.myObject}
<br>Session scope? ${not empty sessionScope.myObject}
<br>Application scope? ${not empty applicationScope.myObject}

The above example should return true for one of the scopes where it is actually been set.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签